实现记事本功能的教程??
实现记事本功能的教程??
实现记事本功能的教程??
2016-11-25
public class MainActivity extends Activity implements OnItemClickListener,OnItemLongClickListener { String tishiString []={"1.单机可以编辑备忘录","2.单机可以编辑备忘录","3.","4.","5.","6.","7.","8.","9.","10.",}; private ListView lv; ArrayAdapter<String>tishiAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv=(ListView) findViewById(R.id.listView); tishiAdapter=new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, tishiString); lv.setAdapter(tishiAdapter); lv.setOnItemClickListener(this); lv.setOnItemLongClickListener(this); } @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Intent it =new Intent(this,EditActivty.class); //intent.putExtra("编号", arg2+1); it.putExtra("备忘", tishiString[arg2]); //it.putExtra("时间", new Date().toString());//获取当前时间 startActivityForResult(it,arg2); } @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub tishiString[arg2]=(arg2+1)+"."; tishiAdapter.notifyDataSetChanged();//数据源改变适配器更新 return true; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode==RESULT_OK) { String str=data.getStringExtra("内容"); String time =data.getStringExtra("时间"); tishiString[requestCode]=time+"\n"+str; tishiAdapter.notifyDataSetChanged(); Toast.makeText(this,"备忘录创建的时间是"+time, 1000).show(); } } }
public class EditActivty extends Activity implements OnClickListener{
private TextView tv;
private EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
Intent it=getIntent();
//int no=it.getIntExtra("编号", 0);
String s=it.getStringExtra("备忘");
//String time =it.getStringExtra("时间");
Button chucunbtn = (Button) findViewById(R.id.chucun_button);
Button quxiaobtn = (Button) findViewById(R.id.quxiao_button);
tv=(TextView) findViewById(R.id.textView);
//tv.setText(no+".");
tv.setText(s.substring(0, 2));
et=(EditText) findViewById(R.id.ET);
if(s.length()>3){
et.setText(s.substring(2));
}
chucunbtn.setOnClickListener(this);
quxiaobtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.chucun_button:
Intent data=new Intent();
data.putExtra("内容" ,tv.getText()+""+et.getText());
data.putExtra("时间",new Date().toString() );
setResult(RESULT_OK, data);
finish();
break;
case R.id.quxiao_button:
setResult(RESULT_CANCELED);
finish();
break;
}
}
}
举报