-3
public class Titles extends Fragment {
View view;
SimpleCursorAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
MySqlite db=new MySqlite(getActivity());
view= inflater.inflate(R.layout.fragment_titles, container, false);
ListView list=(ListView)view.findViewById(R.id.list);
Cursor all_titles = db.getTitle();
adapter = new SimpleCursorAdapter(getActivity().getBaseContext(),
R.layout.fragment_titles,
all_titles,
new String[] { db.KEY_TITLE},
new int[] { R.id.tv_title }, 0);
//Attach cursor adapter to the ListView
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity().getApplicationContext(),"ListView Clicked Go Ahead",Toast.LENGTH_LONG).show();
TextView tv=(TextView)view.findViewById(R.id.tv_title);
String selected_title=tv.getText().toString();
// Launching new Activity on selecting single List Item
Intent i = new Intent(getActivity().getApplicationContext(), Poem.class);
// sending data to new activity
i.putExtra("title", selected_title);
startActivity(i);
}
});
return view;
}
}
我剛剛開始Android開發,和我的工作得到具有點擊的片段的ListView項目問題複選框working.I'm自定義列表視圖。在模擬器中,listview click事件不起作用。我正在使用片段。 任何人都可以幫忙。 在此先感謝列表視圖onItemClickListener不工作