gpt4 book ai didi

java - 在 setAdapter 上,它不会调用 Adapter 的 getView 方法

转载 作者:行者123 更新时间:2023-12-01 11:10:28 25 4
gpt4 key购买 nike

问题是即使我在 listView 上执行 setAdapter , getView 方法也不会被调用。请参阅下面的代码。我没有收到任何错误消息。它只是不显示审阅者数据。请您建议我做错了什么。

MovieReviewerFragmemt 类我有以下代码:

    @Override
protected void onPostExecute (ArrayList movieDetailsArray){
getMovieArrayList(movieDetailsArray);
ListView listView = (ListView) rootView.findViewById(R.id.movie_detail_reviewerlist);
MovieAddlDetail detail = (MovieAddlDetail) movieDetailsArray.get(0);
MovieReviewers[] list = detail.getReviewerArrayList();
Log.v(LOG_TAG, "MovieReviewerFragment - CustomReviewerAdapter - calling adapter");
movieDetailAdapter = new CustomReviewerAdapter(getActivity(), list);
movieDetailAdapter.notifyDataSetChanged();
listView.setAdapter(movieDetailAdapter);
}

CustomerReviewAdapter:

public class CustomReviewerAdapter extends ArrayAdapter {
private Context context;
private LayoutInflater inflater;
private final String LOG_TAG1 = CustomReviewerAdapter.class.getSimpleName();
private MovieReviewers[] reviewers;

public CustomReviewerAdapter(Context context, MovieReviewers[] reviewers) {
super(context, R.layout.fragment_detail, reviewers);
Log.v(LOG_TAG1, "CustomReviewerAdapter - constructor");
this.context = context;
this.reviewers = reviewers;

inflater = LayoutInflater.from(context);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.v(LOG_TAG1, "CustomReviewerAdapter - getView");
if (convertView == null) {
inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.fragment_detail_reviewer, parent, false);
Log.v(LOG_TAG1, "CustomReviewerAdapter - getView - convertview was null");

}
TextView textView1 = (TextView) convertView.findViewById(R.id.movie_detail_reviewerlist_author);
TextView textView2 = (TextView) convertView.findViewById(R.id.movie_detail_reviewerlist_content);
textView1.setText(reviewers[position].getAuthor());
textView2.setText(reviewers[position].getContent());
Log.v(LOG_TAG1, "CustomReviewerAdapter - getView - data set");
return convertView;
}

}

fragment 详细信息审阅者:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id ="@+id/imageView_layout"
android:orientation = "vertical">

<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/movie_detail_reviewerlist_author"
android:textAlignment="center"
android:textStyle="bold"
android:gravity="center_vertical"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:descendantFocusability="blocksDescendants"/>

<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/movie_detail_reviewerlist_content"
android:textAlignment="center"
android:textStyle="bold"
android:gravity="center_vertical"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceLarge"
android:descendantFocusability="blocksDescendants"/>

fragment 详细信息:

<?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">

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/movie_detail_list"
android:editable="false" />

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/movie_detail_reviewerlist"
android:editable="false" />

下面是正在启动 fragment 的 Activity 。第一个 fragment 工作正常并且正在显示。然而,第二个 fragment 是我没有显示任何内容的地方。下面是启动两个 fragment 的正确方法吗?

详细 Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Bundle extras = getIntent().getExtras();
intentData = extras.getStringArray("moviedetails");
MovieDetailFragment movieDetailFragment = new MovieDetailFragment();
movieDetailFragment.setMovieDetails(intentData);
MovieReviewerFragment movieReviewerFragment = new MovieReviewerFragment();
movieReviewerFragment.setMovieDetails(intentData);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container_1, movieDetailFragment)
.add(R.id.container_2, movieReviewerFragment)
.commit();
}
}

最佳答案

您必须像这样调用 LayoutInflater:

inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

关于java - 在 setAdapter 上,它不会调用 Adapter 的 getView 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32445294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com