gpt4 book ai didi

java - 子 ListView 不起作用

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

我正在编写一个模拟 http://www.rottentomatoes.com/mobile/ 的 Android 应用程序网站我在 listView 中有一个电影列表,当我单击单个电影时,我想要一个评论列表(如果您单击该网站,您将看到它们),但是当我单击时,我的应用程序停止工作

主要 Activity

public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
System.out.println ("clicked");
Movie data = (Movie) adapter.getItem(position);
String url = data.getLinks().getReviews();
System.out.println (url);
Intent intent = new Intent();
intent.setClass(getActivity(), MovieDetailsActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);

}

第二个 Activity - 假设启动一个列表

package charnetskaya.rottentomatoes;


public class MovieDetailsActivity extends Activity {

static String url;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.movie_details);

if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}

System.out.println("CREATED");
Intent intent = getIntent();
Uri uri = intent.getData();
url = uri.toString();
}

public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

public static class PlaceholderFragment extends Fragment implements
OnItemClickListener {

private ReviewsAdapter adapter;

public PlaceholderFragment() {

}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.movie_details, container,
false);
ListView list = (ListView) rootView.findViewById(R.id.reviewsList);
adapter = new ReviewsAdapter(inflater);
list.setAdapter(adapter);
System.out.println("HERE");
DownloadReviews task = new DownloadReviews(url);
task.execute(new Void[0]);
System.out.println("THERE");
return list;

}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub

}

}

}

错误信息 enter image description here

最佳答案

在您的 PlaceholderFragment onCreateView 中尝试返回 rootView 而不是 list

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.movie_details, container,
false);
ListView list = (ListView) rootView.findViewById(R.id.reviewsList);
adapter = new ReviewsAdapter(inflater);
list.setAdapter(adapter);
System.out.println("HERE");
DownloadReviews task = new DownloadReviews(url);
task.execute(new Void[0]);
System.out.println("THERE");
return rootView;

}

关于java - 子 ListView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24170790/

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