我该怎么让特定的列到列表视图中的Android [英] How can i show a particular column to list view in android
本文介绍了我该怎么让特定的列到列表视图中的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想说明的setName列的列表视图它是如何可能的机器人。
我分享我的code。
I want to show setName column as a list view how it is possible in android. I am share my code.
private String lv_arr[];
String selectList = "select setName from Displaysettings";
DBConnect conn1 = new DBConnect(getApplicationContext(), "colorCode");
conn1.execNonQuery(selectList);
lv1=(ListView)findViewById(R.id.ListView01);
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
先谢谢了。
推荐答案
你可以尝试这样的事:
String[] setNameValues = new String[] {
"setName1",
"setName2",
"setName3"
};
// Create a simple array adapter (of type string)
//with the setName values returned by conn1.execNonquery
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, setNameValues);
所以,你应该转换conn1.execNonQuery(选择列表),结果一个字符串数组
So, you should convert your conn1.execNonQuery(selectList) result to a string array
更新:
或者你也可以使用游标适配器,如果你的conn1.execNonQuery返回游标。
Or you can use a cursor adapter, if your conn1.execNonQuery return a cursor.
例如(某些行删除要清楚)
For example (some lines are delete to make it clear)
public class DiagramListCursorAdapter extends CursorAdapter {
private boolean dataValid;
private boolean autoRequery;
private boolean autoRequeryInProgress;
private int count = -1;
public DiagramListCursorAdapter(Context context, Cursor c, boolean autorequery) {
super(context, c, autorequery);
}
@Override
public View newView(final Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.diagram_item, null);
DiagramListCursorWrapper wrapper;
wrapper = new DiagramListCursorWrapper(v);
v.setTag(wrapper);
return v;
}
@Override
public void bindView(View v, Context context, Cursor cursor) {
DiagramListCursorWrapper wrapper = (DiagramListCursorWrapper) v.getTag();
wrapper.populateFrom(cursor);
}
void refresh() {
if (getCursor() != null) {
getCursor().requery();
}
}
public class DiagramListCursorWrapper {
TextView title;
public DiagramListCursorWrapper(View v) {
setupViews(v, null);
}
public DiagramListCursorWrapper(View v, Context context) {
setupViews(v, context);
}
private void setupViews(View v, Context context) {
title = (TextView) v.findViewById(R.id.title);
icon = (ImageView) v.findViewById(R.id.icon);
}
public void populateFrom(Cursor cursor) {
if (cursor != null) {
try {
title.setText(cursor.getString(cursor.getColumnIndex(DiagramsADO.DIAGRAM_TITLE)));
} catch (Exception e) {
}
}
}
}
}
我希望这可以帮助你。
I hope this helps you
这篇关于我该怎么让特定的列到列表视图中的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文