public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textView;
listView = (ListView)this.findViewById(android.R.id.list);
List<Map<String,Object>> appItems=new ArrayList<Map<String,Object>>();
// Map<String,Object> aitem=new HashMap<String,Object>();
for(int i=0;i<app.length;i++){
Map<String,Object> aitem=new HashMap<String,Object>();
aitem.put("img", photo[i]);
aitem.put("tu", app[i]);
aitem.put("tu1", data[i]);
appItems.add(aitem);
}
System.out.println(appItems.size());
SimpleAdapter simpleAdapter=new SimpleAdapter(this,appItems,R.layout.my_list_item,
new String[]{"img","tu","tu1"},new int[]{R.id.imageview0,R.id.text0,R.id.text00});
System.out.println(simpleAdapter == null);
System.out.println(listView == null);
listView.setAdapter(simpleAdapter);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
// public void onItemClick(AdapterView<?> parent, View view,
// int position, long id) {
// if(position == 0 && id == 0){
// Intent intent=new Intent();
// intent.putExtra("one", 0);
// intent.setClass(Major.this,Constell.class);
// Major.this.startActivity(intent);
// }
// }
//
// }这是第一个类实现。单击传一值并跳转一个新的Activity,希望实现跳转时,在新类判断只要单击的与数据的id相同,将读取数据库内容,并在这个界面显示。以下的实现有很多问题,大家帮我看看。如何能实现我说的效果。protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView=(TextView)findViewById(R.id.textview);
database=openDatabase();
// String sql="select details from xingzuo where twelve=?";
// Cursor cursor=database.rawQuery(sql, null);
Cursor cursor = database.query("xingzuo", new String[]{"id"}, null, null, null, null, "desc");
int id = 0;
while(cursor.moveToNext()){
Double d = cursor.getDouble(1);//然后将double装换成int值
id=d.intValue(); //或者cursor.getCount();
}
Intent intent=getIntent();
switch(id){
case 0:
String s=intent.getStringExtra("one");
int in;
in=s.indexOf(s);
if(id==0&&id==in){
textView.setText(cursor.getString(cursor.getColumnIndex("details")));
this.setContentView(R.layout.showtext);
}
} }
private SQLiteDatabase openDatabase() {
try{
String databaseFilename=DATABASE_PATH+"/"+DATABASE_FILENAME;
File dir=new File(DATABASE_PATH);
if(!dir.exists())
dir.mkdir();
if(!(new File(databaseFilename)).exists())
{
InputStream is=getResources().openRawResource(R.raw.c);
FileOutputStream fos=new FileOutputStream(databaseFilename);
byte[] buffer=new byte[8192];
int count=0;
while((count=is.read(buffer))>0){
fos.write(buffer,0,count);
}
fos.close();
is.close();
}
SQLiteDatabase database=SQLiteDatabase.openOrCreateDatabase(databaseFilename, null);
return database;
}
catch(Exception e){
}
return null;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货