我有一个线性布局中的列表视图和一个按钮。我无法扩展ListActivity(使用Onlistitemclick),但我必须在列表视图中选择一个项目,该项目打开另一个视图,我必须从SQLite DB中填写详细信息。在项目点击列表视图
什么是实现这个以下代码假设数据库作品的最佳方法是什么?我是一名初学者。所有有关该方法和代码的建议都是受欢迎的。
由于提前,
public class Contacts extends Activity implements OnClickListener {
int NewContact_Request_Code = 1;
Button newcontact;
ListView listview;
public static final String LOG_TAG = "Contacts";
int mInt = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contactview);
// Set the content to contactview.xml
// newcontact = NEW CONTACT button
// listview = MyList List View
newcontact = (Button) findViewById(R.id.baddcontact);
listview = (ListView) findViewById(R.id.mylist);
// Make a New Database
DBContact info = new DBContact(this);
// Open , get Information from database and close it
info.open();
String[] data = info.queryAll();
info.close();
// listview = getListView();
listview.setTextFilterEnabled(true);
// Display the names
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Contacts.this, android.R.layout.simple_list_item_1, data);
listview.setAdapter(adapter);
newcontact.setOnClickListener(this);
}
// @Override
// protected void onListItemClick(ListView l, View v, int position, long id)
// {
// // TODO Auto-generated method stub
// super.onListItemClick(l, v, position, id);
// Intent viewintent = new Intent(Contacts.this, ViewContact.class);
// String item = (String) getListAdapter().getItem(position);
// viewintent.putExtra("name_clicked", item);
// startActivity(viewintent);
//
// }
public void onClick(View v) {
// TODO Auto-generated method stub
Intent newintent = new Intent(Contacts.this, AddNewContact.class);
// start actiivity for result - to get the name of the new contact
startActivityForResult(newintent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
// pass the value of the string via cursor and update the list
}
}
我真的很抱歉,我一直在做几个星期之前从android.ould你请解释一下? – chitranna
@ user1693503我将解释什么。你想知道如何处理那个? – Praveenkumar
这将有很大的帮助,如果你could.There是复制没有意义和粘贴code.I很新的编程和我没有一个软件回地面了。 我的列表视图是一个名称列表。当其中一个被点击时,我想将该名称参数传递给另一个类。这是什么?我知道如何使用意图和意向发送数据 – chitranna