0
|Title | Subcategory | Details |
|-------------------------------|
|Song | TAMIL SONG | Yuvan |
|-------------------------------|
|Song | English |Tom |
|-------------------------------|
|Movie | mal | abcd |
|-------------------------------|
|Movie | Telugu |TomCuirse |
|-------------------------------|
|Sounds | mal | abcd |
我有這樣的列名稱列表。我想根據標題的選擇顯示子類別字段。我們如何編寫一個查詢,我們如何將它附加到列表視圖上的ArrayAdapter?在DATAS canot在列表視圖可以持續顯示TextView的是空的,但列表視圖可什麼是查詢來獲取列名稱?
Subcategor類
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subcategory_layout);
listView= (ListView) findViewById(R.id.listView2);
//Intent i = getIntent();
dbHelper = new SqlLiteDbHelper(this);
try {
dbHelper.openDataBase();
} catch (SQLException e) {
e.printStackTrace();
}
sqLiteDatabase=dbHelper.getReadableDatabase();
cursor=dbHelper.getsubcategory(sqLiteDatabase);
subcategoryAdapter = new SubcategoryAdapter(getApplicationContext(),R.layout.sublist_item);
listView.setAdapter(subcategoryAdapter);
if (cursor.moveToFirst())
{
do {
String subcategory;
subcategory=cursor.getString(0);
foodSupply= new FoodSupply(subcategory);
subcategoryAdapter.add(foodSupply);
}while (cursor.moveToNext());
}enter code here
SubcategoryAdapter
public class SubcategoryAdapter extends ArrayAdapter {
List list = new ArrayList();
public SubcategoryAdapter(Context context, int resource) {
super(context, resource);
}
@Override
public void add (Object object){
super.add(object);
list.add(object);
}
static class LayoutHandler {
TextView SUBCATEGORY;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem (int position){
return list.get(position);
}
@Override
public View getView (int position, View convertView, ViewGroup parent){
View row = convertView;
LayoutHandler layoutHandler;
if (row == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.sublist_item, parent, false);
layoutHandler = new LayoutHandler();
layoutHandler.SUBCATEGORY = (TextView) row.findViewById(R.id.textView2);
row.setTag(layoutHandler);
} else {
layoutHandler = (LayoutHandler) row.getTag();
}
FoodSupply foodSupply = (FoodSupply) this.getItem(position);
layoutHandler.SUBCATEGORY.setText(foodSupply.getSubcategory());
return row;
}enter code here
謝謝但是,當我在列表視圖中單擊標題名稱與該標題名稱相關的子類別字段想顯示在另一個列表視圖!所以我們想在該setOnItemClickListener中使用遊標? – Karthick
您可以單擊標題,然後將其插入到onItemClickListener的查詢中(如果符合您的用例)。上面的代碼只是讓你獲得子類別列表的方法,你以後如何使用它是取決於你的。 – RobVoisey
字段已經插入!!我只是想在列表視圖中顯示列名..我已經在列表視圖中使用Arrayadapter自定義佈局顯示標題,現在單擊該標題時,與該標題相關的字段要顯示在新的列表中活動... PLZ幫助3,4天即時鎖定那裏,我現在不知道如何做到這一點:( – Karthick