简体   繁体   中英

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

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 .

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;

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM