我有一個線性佈局中的列表視圖和一個按鈕。我無法擴展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