[英]child ListView doesn't work
i am writing an android app that simulates http://www.rottentomatoes.com/mobile/ web site I have a list of movies in the listView and when i click on a single movie i want to have a list of reviews (if you click on the web site you will see them) however my application stops working when i click 我正在编写一个模拟http://www.rottentomatoes.com/mobile/网站的android应用程序,我在listView中有一个电影列表,当我单击单个电影时,我想要一个评论列表(如果您单击该网站,您将看到它们),但是当我单击时,我的应用程序停止工作
MainActivity 主要活动
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);
}
Second Activity - that suppose to start a list 第二个活动-假设开始一个列表
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
}
}
} }
the error message 错误信息
In your PlaceholderFragment
onCreateView
try to return rootView
not a list
. 在您的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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.