我已经编写了从下面所示的一些数组中创建列表的代码! 代码运行正常,输出符合预期!
为有相同问题的人更新: nice tutorial for custom listview
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView1 = (ListView) findViewById(R.id.listView1);
String[] items = { "some", "fancy", "items", "to", "show" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.listitem, items);
listView1.setAdapter(adapter);
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
</RelativeLayout>
listview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="22dp"
android:gravity="center_horizontal"
/>
我想要完成什么?
将每个列表项中文本的颜色和字体更改为不同的颜色和字体...并在点击它们时执行一些任务...
是否可以在同一个 ListView 中获取另一个 ListView 例如。如果我单击一个列表项,它会再次显示一个列表(一种子列表),在同一 Activity (或屏幕)上包含不同的列表项。点击子列表项可以执行一些操作。
详细的答案非常感谢,因为我是 Android 开发的新手。 谢谢!
最佳答案
1.change color and font of the text in each list item to a different one..and do some task on
tapping on them...
- 创建一个自定义适配器,覆盖该适配器的
getVIew()
并创建 颜色和文本发生变化。 - 覆盖 ListView 的
onItemClick()
。完成点击事件 对于列表项。
现在
2. also is it possible to get another listview inside the same listview eg. if I click on a
list item it again shows me a list (kind of a sub list) with different list items on that
same activity(or screen).and some action could be done on tapping the sub list items.
3. what are my other list styling options..
- 它是 Expandable ListView只需查看链接即可了解更多信息 信息。
关于java - 使用数组列表适配器设置 android listview 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14354705/