हाँ आप यह कर सकते में बहुत तेजी से पूरी अवधारणा को समझने के लिए। इसे डीबी से लाने के लिए डेटा एक्सचेंज क्लास बनाएं .. स्ट्रिंग्स को एक ऐरे में स्टोर करें।
डेटाबेस से प्राप्त स्ट्रिंग्स की सरणी प्रदर्शित करने के लिए एक ArrayAdapter बनाएँ।
उदाहरण
के लिए
public class AndroidListViewActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
String[] numbers = {"one","two","three","four"}
// here you store the array of string you got from the database
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, numbers));
// refer the ArrayAdapter Document in developer.android.com
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String num = ((TextView) view).getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
i.putExtra("number", num);
startActivity(i);
}
});
}
}
secondActivity विशेष आइटम आप क्लिक किया है
public class SingleListItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.single_list_item_view);
TextView txtProduct = (TextView) findViewById(R.id.product_label);
Intent i = getIntent();
// getting attached intent data
String product = i.getStringExtra("number");
// displaying selected product name
txtProduct.setText(product);
}
}
होना चाहिए आप तदनुसार विभिन्न लेआउट फ़ाइलों को बनाने के लिए है प्रदर्शित करने के लिए .. आशा इस मदद करता है :)