我没有用elipse自带的ListView. 自己做了一个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="TextView01"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="wrap_content"
android:layout_marginRight="100dp"
android:id="@+id/ItemTitle"
/>
<TextView
android:text="TextView02"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="wrap_content"
android:layout_below="@+id/ItemTitle"
android:id="@+id/ItemText"
/>
</LinearLayout> //绑定Layout里面的ListView
ListView list = (ListView) findViewById(R.id.ListView01);
//生成动态数组,加入数据
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
for(int i=0; i<4; i++)
{
HashMap<String, Object> map = new HashMap<String,Object>();
map.put("ItemText", "hello");
map.put("ItemTile", "Level" + i);
listItem.add(map);
}
//生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdatperAdapter = new SimpleAdapter(this, listItem,
R.layout.list_items,
new String[]{"ItemText","ItemTile"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
//添加并显示
list.setAdapter(listItemAdatperAdapter);
//添加点击
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("点击第"+arg2+"个项目");
}
});
现在显示工作OK. 我想增加一个功能就是选中该行时候, 该行处于被选择状态, 比如该行背景为灰色.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="TextView01"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="wrap_content"
android:layout_marginRight="100dp"
android:id="@+id/ItemTitle"
/>
<TextView
android:text="TextView02"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_width="wrap_content"
android:layout_below="@+id/ItemTitle"
android:id="@+id/ItemText"
/>
</LinearLayout> //绑定Layout里面的ListView
ListView list = (ListView) findViewById(R.id.ListView01);
//生成动态数组,加入数据
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
for(int i=0; i<4; i++)
{
HashMap<String, Object> map = new HashMap<String,Object>();
map.put("ItemText", "hello");
map.put("ItemTile", "Level" + i);
listItem.add(map);
}
//生成适配器的Item和动态数组对应的元素
SimpleAdapter listItemAdatperAdapter = new SimpleAdapter(this, listItem,
R.layout.list_items,
new String[]{"ItemText","ItemTile"},
new int[] {R.id.ItemTitle,R.id.ItemText}
);
//添加并显示
list.setAdapter(listItemAdatperAdapter);
//添加点击
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("点击第"+arg2+"个项目");
}
});
现在显示工作OK. 我想增加一个功能就是选中该行时候, 该行处于被选择状态, 比如该行背景为灰色.
解决方案 »
- 录音格式转换成wav格式
- jni调用c库socket失败
- 【求救】eclipse环境配置问题
- 关于android 问题,,在android编程中如何获得GSM手机当前的lac、cid!我只能获得邻近小区的请问如何获得当前正在用的呢??
- 汉字识别 问题
- android版本号和Linux内核的版本号必须对应吗?
- android在数据库中删除符合多个条件的数据
- 安卓怎么实现计算纪念日
- Cursor 放在finilly中也关不掉 报错,闪退
- android简单开发,使用bmob作为服务器后端,上传图片到bmob失败
- 找android的触屏版俄罗斯方块游戏源码
- Activity跳转、返回和关闭的相关问题。
/**
* A list view where the last item the user clicked is placed in
* the "activated" state, causing its background to highlight.
*/
public class List17 extends ListActivity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // Use the built-in layout for showing a list item with a single
// line of text whose background is changes when activated.
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_activated_1, mStrings));
getListView().setTextFilterEnabled(true);
// Tell the list view to show one checked/activated item at a time.
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Start with first item activated.
// Make the newly clicked item the currently selected one.
getListView().setItemChecked(0, true);
} @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Make the newly clicked item the currently selected one.
getListView().setItemChecked(position, true);
} private String[] mStrings = Cheeses.sCheeseStrings;
}
我增加这条. 编译报错. 请问如何解决
getListView().setItemChecked(arg2, true);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
setTitle("点击第"+arg2+"个项目");
getListView().setItemChecked(arg2, true);
}
});
报错:
The method getListView()is undefined for the type new AdapterView.OnItemClickListener()是不是我加错地方了.