Skip to content

Commit

Permalink
hzuapps#5 hzuapps#1094 231第五次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
zglx committed May 15, 2018
1 parent 2aa82a1 commit 62fd1fa
Showing 1 changed file with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.service.autofill.FillEventHistory;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.FileInputStream;
import java.io.FileOutputStream;


public class SecActivity extends Activity implements View.OnClickListener{
/**
* 顶部内容栏
Expand All @@ -23,9 +30,11 @@ public class SecActivity extends Activity implements View.OnClickListener{
private TextView tv_nab;
/**
*
* 中间内容栏,还没有编写
* 中间内容栏
*/
private FrameLayout mBodylayout;
private ArrayAdapter<String> adapter;
private ListView listView;
/*
底部内容栏
*/
Expand All @@ -36,6 +45,8 @@ public class SecActivity extends Activity implements View.OnClickListener{
private TextView tv_play;
private ImageView iv_wenzi;
private ImageView iv_bofang;
private String[] data = { "中超第一轮精彩回放", "中超第二轮精彩回放", "中超第三轮精彩回放", "中超第四轮精彩回放","中超第五轮精彩回放" };
private String[] data1 = { "中超第一轮精彩赛事", "中超第二轮精彩赛事", "中超第三轮精彩赛事", "中超第四轮精彩赛事","中超第五轮精彩赛事" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -45,6 +56,66 @@ protected void onCreate(Bundle savedInstanceState) {
setListener();
setInitStatues();
setTopStatues(0);
String msg=read();
refreshRecord(msg);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String msg = adapter.getItem(position).toString();
if (!msg.isEmpty())
write(msg);
msg = read();
Toast.makeText(SecActivity.this,msg,Toast.LENGTH_SHORT).show();
refreshRecord(msg);
Intent intent = new Intent(SecActivity.this, ThreeActivity.class);
startActivity(intent);
}
});
}
/*
数据读取,读取最后一次观看的记录 */
public String read() {
try {
FileInputStream inStream = this.openFileInput("record.txt");
byte[] buffer = new byte[1024];
int hasRead = 0;
StringBuilder sb = new StringBuilder();
while ((hasRead = inStream.read(buffer)) != -1) {
sb.append(new String(buffer, 0, hasRead));
}
inStream.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/*
数据写入,写入最后一次观看的记录
*/
public void write(String msg){
// 步骤1:获取输入值
if(msg == null) return;
try {
// 步骤2:创建一个FileOutputStream对象,MODE_APPEND追加模式
FileOutputStream fos = openFileOutput("record.txt",
MODE_PRIVATE);
// 步骤3:将获取过来的值放入文件
fos.write(msg.getBytes());
// 步骤4:关闭数据流
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/*
添加最后一次浏览的信息
*/
private void refreshRecord(String msg)
{
TextView tv_record=(TextView)findViewById(R.id.record);
String s = tv_record.getText().toString();
tv_record.setText(read());
}
private void init()//给控件赋值
{
Expand All @@ -60,17 +131,24 @@ private void init()//给控件赋值
tv_play = (TextView) findViewById(R.id.tv_play);
iv_wenzi = (ImageView) findViewById(R.id.iv_wenzi);
iv_bofang = (ImageView)findViewById(R.id.iv_bofang);

listView = (ListView)findViewById(R.id.ni);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.mCharacter:
adapter = new ArrayAdapter<String>(
SecActivity.this, android.R.layout.simple_list_item_1, data1);

listView.setAdapter(adapter);
clearBottom();
setSelectStatues(0);
break;
case R.id.mPlay:
adapter = new ArrayAdapter<String>(
SecActivity.this, android.R.layout.simple_list_item_1, data);

listView.setAdapter(adapter);
clearBottom();
setSelectStatues(1);
break;
Expand Down Expand Up @@ -152,6 +230,10 @@ private void setSelectStatues(int index)
case 0:
mCharacter.setSelected(true);
tv_characetr.setTextColor(Color.parseColor("#0097F7"));
adapter = new ArrayAdapter<String>(
SecActivity.this, android.R.layout.simple_list_item_1, data1);
listView = (ListView) findViewById(R.id.ni);
listView.setAdapter(adapter);
break;
case 1:
mPlay.setSelected(true);
Expand All @@ -168,5 +250,4 @@ private void setInitStatues()
/*
设置初始状态值
*/

}

0 comments on commit 62fd1fa

Please sign in to comment.