Android DialogFragment不会从布局中膨胀所有内容
我有一个用于搜索结果的自定义dialogfragment,还有一个带有ListView的TextView,标题应该在其中Android DialogFragment不会从布局中膨胀所有内容,android,user-interface,listview,android-listview,Android,User Interface,Listview,Android Listview,我有一个用于搜索结果的自定义dialogfragment,还有一个带有ListView的TextView,标题应该在其中 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_paren
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/res"
android:textStyle="bold"
android:textSize="36sp"
android:textColor="@color/button"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/list" />
</LinearLayout>
但是它不显示TextView,即使ListView在那里并且完全由自定义适配器填充
类JSONAdapter扩展BaseAdapter实现ListAdapter{
private final Activity activity;
private final JSONArray jsonArray;
private JSONAdapter(Activity activity, JSONArray jsonArray) {
assert activity != null;
assert jsonArray != null;
this.jsonArray = jsonArray;
this.activity = activity;
}
@Override public int getCount() {
return jsonArray.length();
}
@Override public JSONObject getItem(int position) {
return jsonArray.optJSONObject(position);
}
@Override public long getItemId(int position) {
JSONObject jsonObject = getItem(position);
return jsonObject.optLong("id");
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = activity.getLayoutInflater().inflate(R.layout.simple_list_item, parent,false);
Double score= 0.0;
JSONObject jsonObject = getItem(position);
TextView firstline= (TextView) convertView.findViewById(R.id.firstLine);
TextView secondline = (TextView) convertView.findViewById(R.id.secondLine);
TextView confidence = (TextView) convertView.findViewById(R.id.score);
try {
firstline.setText(jsonObject.getString("title"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
score= Double.valueOf(jsonObject.getString("score"));
confidence.setText(jsonObject.getString("score"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
secondline.setText(jsonObject.getString("text"));
} catch (JSONException e) {
e.printStackTrace();
}
if (score<=0.1)
{
convertView.setBackgroundColor(getResources().getColor(R.color.red));
}
if (score>0.1)
{
convertView.setBackgroundColor(getResources().getColor(R.color.orangish));
}
if (score>=0.3)
{
convertView.setBackgroundColor(getResources().getColor(R.color.yellow));
}
if (score>=0.5)
{
convertView.setBackgroundColor(getResources().getColor(R.color.green));
}
return convertView;
}
}
在这里传递所有代码
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = (View)inflater.inflate(R.layout.activity_result,null);
像这样创建视图
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_result, container,false);
}
现在一切都应该好了充气机的方法是什么。充气??如果代码中充气线下有其他代码,请复制这些代码并将其放置在onViewCreated中,并使用getView作为父视图@Kameegamingany feedback@Kameegaming
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = (View)inflater.inflate(R.layout.activity_result,null);
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_result, container,false);
}