У меня есть собственный диалоговый фрагмент для результатов поиска, и у меня есть TextView с ListView, где должно быть название.DialogFragment не раздувает все из макета
<?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>
Вот OnCreate Dialog
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = (View)inflater.inflate(R.layout.activity_result,null);
Но он не показывает 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;
}
}
Почему это происходит?
UPDATE:
У меня также есть этот метод
public static SearchDialogFragment newInstance(String title) {
SearchDialogFragment frag = new SearchDialogFragment();
Bundle args = new Bundle();
args.putString("json", title);
frag.setArguments(args);
return frag;
}
Не работает, не может переустановить метод надуть – KameeCoding
какой метод надувной. если есть другие коды под линией инфляции в вашем коде, скопируйте их и поместите их в 'onViewCreated()' и используйте 'getView()' в качестве родительского 'View' @Kameegaming – Elltz
любую обратную связь @Kameegaming – Elltz