昨天碰到一个很奇怪的总是:DialogFragment中ListView的子项显示不可用
有两个同类型的ListView,相同的Adapter,相同的view,内容也相同.唯一区别是一个是放到Fragment中,一个是放到DialogFragment中,结果放到Fragment中显示正常.放到DialogFragment中显示不下常,所有子项全变成灰色了(就是 enable=false的那种灰色).原因不明...
1.这是放在Fragment中ListView中的子项,显示正常
2.这是放在DialogFragment中的ListView中的子项,显示为灰色.
虽然现在显示的两个item长的不一样.但是我自己也用相同的view,相同的adapter试过,放到DialogFragment中的item就是灰色的,不知道什么原因.
现在还没解决,先mark
Code:
1. normal ListView:
public class SearchFragment extends BaseFragment{
ListView searchListView;
SearchListAdapter searchListAdapter;
…
init(){
searchListAdapter = new SearchListAdapter(getActivity(), searchList);
searchListView.setAdapter(searchListAdapter);
}
}
class SearchListAdapter{
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = viewHelper.getView(parent, list, position);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
private static class ViewHelper {
Context context;
public ViewHelper(Context context) {
this.context = context;
}
public View getView(ViewGroup parent, List<Apply> list, int position) {
return getView(parent, list.get(position), position);
}
private View getView(ViewGroup parent, Apply item, int position) {
LayoutInflater inflater = LayoutInflater.from(context);
View convertView = inflater.inflate(R.layout.search_list_item, parent, false);
SearchItemViewHolder holder = new SearchItemViewHolder(convertView);
holder.binderData(position, item);
convertView.setTag(holder);
return convertView;
}
}
}
search_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/bg_list_item"
android:orientation="horizontal">
<TextView
android:id="@+id/no"
style="@style/list_item_no"
android:background="#ff367300"
android:text="@string/dispatch_wait_list_item_no_demo"
android:textSize="36sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/list_item_textview_title"
android:text="@string/proposer" />
<TextView
android:id="@+id/applicant"
style="@style/list_item_textview"
android:layout_width="68dp"
android:text="@string/proposer_demo" />
<TextView
style="@style/list_item_textview_title"
android:text="@string/workgroup" />
<TextView
android:id="@+id/applicant_workgroup"
style="@style/list_item_textview"
android:layout_width="match_parent"
android:text="@string/applicant_workgroup_demo" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
style="@style/list_item_textview_title"
android:text="@string/auditor" />
<TextView
android:id="@+id/auditor"
style="@style/list_item_textview"
android:text="@string/engineer_demo" />
<TextView
style="@style/list_item_textview_title"
android:text="@string/status" />
<TextView
android:id="@+id/status"
style="@style/list_item_textview"
android:layout_width="match_parent"
android:text="@string/status_close" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/list_item_textview_title"
android:text="@string/create_date" />
<TextView
android:id="@+id/create_date"
style="@style/list_item_textview"
android:layout_width="match_parent"
android:text="@string/dispatch_finish_list_item_apply_date_demo" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
2. grey ListView
public class ContractNoPickerDialogFragment extends BaseDialogFragment {
ListView searchListView;
ContractNoAdapter contractNoAdapter;
…
init(){
contractNoAdapter = new ContractNoAdapter(getContext(), searchList);
searchListView.setAdapter(contractNoAdapter);
searchListView.setOnItemClickListener(this);
}
}
class ContractNoAdapter{
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = viewHelper.getView(parent, list, position);
} else {
// holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
private static class ViewHelper {
Context context;
public ViewHelper(Context context) {
this.context = context;
}
public View getView(ViewGroup parent, List<Contract> list, int position) {
return getView(parent, list.get(position), position);
}
private View getView(ViewGroup parent, Contract item, int position) {
LayoutInflater inflater = LayoutInflater.from(context);
View convertView = inflater.inflate(R.layout.contrat_no_list_item, parent, false);
ContractNoItemViewHolder holder = new ContractNoItemViewHolder(convertView);
holder.binderData(position, item);
convertView.setTag(holder);
return convertView;
}
}
}
contrat_no_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/bg_list_item"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<TextView
style="@style/form_row_left"
android:layout_width="wrap_content"
android:text="@string/contract_no" />
<TextView
android:id="@+id/contract_no"
style="@style/form_row_right_text"
android:hint="@string/loading" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
style="@style/form_row_left"
android:layout_width="wrap_content"
android:text="@string/project_name2" />
<TextView
android:id="@+id/project_name"
style="@style/form_row_right_text"
android:hint="@string/loading" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="horizontal">
<TextView
style="@style/form_row_left"
android:layout_width="wrap_content"
android:text="@string/sales" />
<TextView
android:id="@+id/sales"
style="@style/form_row_right_text"
android:hint="@string/loading" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/form_row_left"
android:layout_width="wrap_content"
android:text="@string/start_date" />
<TextView
android:id="@+id/check_start_date"
style="@style/form_row_right_text"
android:hint="@string/loading" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/form_row_left"
android:layout_width="wrap_content"
android:text="@string/end_date" />
<TextView
android:id="@+id/check_end_date"
style="@style/form_row_right_text"
android:hint="@string/loading" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
总算解决了:
在listview的子项中显式调用 setColor,setstyle之类的...
不过还是不太清楚不设置color时,设计UI时显示正常,实机测试为啥就不对了呢?