我想先说一下,即时消息对于android开发来说还是很新的。
我的问题是如何更改以下示例以允许每个列表项的左侧和右侧都显示文本。
我的目的是让每个列表项在左侧都有一个项说明,在右侧具有一个该说明的数值。
我到目前为止所拥有的只是一个列表,该列表显示了我想在每个项目的左侧显示的值。
主要Java活动(NewtestActivity.java):
public class NewtestActivity extends Activity {
String[] exampleList = {
"Item 1",
"Item 2",
"Item 3",
"Test 4",
"Item 5",
"Test 6",
"Item 7",
"Test 8"
//etc etc
};
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get an instance of your listview in code
ListView listview = (ListView) findViewById(R.id.list);
// Set the listview's adapter
listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, exampleList));
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="280dp"
android:layout_height="fill_parent"
>
<ImageView
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginLeft="5dp"
android:text="@string/app_name"
/>
</LinearLayout>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="200dp"
/>
</LinearLayout>
谢谢你的帮助 (:
最佳答案
扩展ArrayAdapter
编辑android.R.layout.simple_list_item_1以包含您的布局
想
Check this example