0
我试图以编程方式更改ListView
中文本的对齐方式,而不是更改xml文件。以编程方式访问rowlistview
这里是我的row_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textViewRowList"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent"
android:textSize="20sp"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:gravity="left"
android:textColor="#330033"
android:textStyle="bold"/>
而且activity_main.xml
有以下ListView
有定义
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="0dp"
tools:listitem="@android:layout/simple_list_item_1"
android:background= "#FF6600">
</ListView>
所以在我mainactivity.java
我想在运行时更改列表视图文本的对齐用户点击时关于我的活动的按钮
private ListView lv;
private TextView tvRowListView;
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row_listview, sampleStringArray));
tvRowListView = (TextView) findViewById(R.id.textViewRowList);
tvRowListView.setGravity(Gravity.CENTER);
然而,上面的最后一行是抛出nullpointerexception。我不知道为什么。有人可以在这里提出一些想法/解决方案
由于性能。我可以在讨论客户适配器问题的论坛中获得更多的问题。我想我现在知道我的问题的出路。 – user1938357