我有一个listview,里面是texview。有时只显示第一个字符。当我刷新视图时,整个单词出现。有没有人经历过这个?我该如何解决这个错误?提前致谢
这是我的代码:
ListView tasksList = (ListView) findViewById(R.id.tasks_list);
tasksListAdapter = new SimpleAdapter(this, tasksListItems, R.layout.advanced_view_row,
new String[] {LIST_ADAPTER_APPLICATION_ICON, LIST_ADAPTER_KEY_NAME, LIST_ADAPTER_KEY_RECEIVED, LIST_ADAPTER_KEY_SENT},
new int[] {R.id.application_icon, R.id.process_name, R.id.received, R.id.sent}
)
{
@Override
@SuppressWarnings("unchecked")
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = LayoutInflater.from(parent.getContext()).
inflate(R.layout.advanced_view_row, parent, false);
}
HashMap<String, Object> item = (HashMap<String, Object>)this.getItem(position);
((ImageView) convertView.findViewById(R.id.application_icon)).setImageDrawable((Drawable) item.get(LIST_ADAPTER_APPLICATION_ICON));
((TextView) convertView.findViewById(R.id.process_name)).setText((String) item.get(LIST_ADAPTER_KEY_NAME));
((TextView) convertView.findViewById(R.id.received)).setText((String) item.get(LIST_ADAPTER_KEY_RECEIVED));
((TextView) convertView.findViewById(R.id.sent)).setText((String) item.get(LIST_ADAPTER_KEY_SENT));
return convertView;
};
};
tasksList.setAdapter(tasksListAdapter);
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="5dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TableRow>
<TextView
android:id="@+id/status"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:layout_weight="0.01"/>
<ImageView
android:id="@+id/application_icon"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_weight="0.09"/>
<TextView
android:id="@+id/process_name"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.4"/>
<TextView
android:id="@+id/received"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.25"
android:gravity="right"/>
<TextView
android:id="@+id/sent"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="0.25"
android:gravity="right"/>
</TableRow>
</TableLayout>
答案 0 :(得分:0)
将id = application_icon 的 TextView 的layout_width更改为0dip(而不是32dip)。
在哪个TextView中只显示一个字符?