这里是我的一些主要活动代码,我将我的sqlite信息插入列表视图。任何人都可以告诉我如何将数据插入到自定义列表视图中。任何人都可以告诉我该怎么做。
MainActivity.java
ListView lst;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lst=(ListView)findViewById(R.id.list_xml);
lst.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(MainActivity.this,ContactActivity.class);
Bundle b=new Bundle();
b.putInt("position",i);
intent.putExtras(b);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.add_contact_menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.add_contact:
startActivity(new Intent(MainActivity.this,ContactActivity.class));
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
DBHelper db=new DBHelper(this);
ArrayList<String> names=new ArrayList<String>();
for (int i=0;i<db.getAllcontact().size();i++)
names.add("Total Earn:"+db.getAllcontact().get(i).getName()+"\nCategorey:"+db.getAllcontact().get(i).getAddress()+"\nSAVE"+db.getAllcontact().get(i).getPhone());
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,names);
lst.setAdapter(adapter);
super.onResume();
}