gpt4 book ai didi

android - 点击ListView时出错,D/ViewRootImpl : ViewPostImeInputStage processPointer 0 D/ViewRootImpl: ViewPostImeInputStage processPointer 1

转载 作者:行者123 更新时间:2023-11-30 00:33:10 30 4
gpt4 key购买 nike

您好,我正在尝试学习 Android 开发,并且正在构建一个新应用程序。我已经实现了一个 ListFragment 和一个适配器来显示一些注释。注释按我的意愿显示,但现在当我单击一个项目时,我无法触发另一个 Activity ,我在日志中看到上面的错误。我的代码如下所示。

这是主要 fragment

 public class MainListFragment extends ListFragment {

private ArrayList<NoteStructure> notes;
private NoteAdapter noteAdapter;
public MainListFragment() {
// Required empty public constructor
}


public void onActivityCreated(Bundle savedInstanceState){

super.onActivityCreated(savedInstanceState);

notes = new ArrayList<NoteStructure>();
notes.add(new NoteStructure("malakia", "sdfsfsdfffffffsdfsfsfdfsfsds"));
notes.add(new NoteStructure("sou gamw", "gamithikessssssssssssssssssssssssssssssssss"));
noteAdapter = new NoteAdapter(getActivity(),notes);
setListAdapter(noteAdapter);
}
public void onListItemClick(ListView listView, View view, int position, long id){

super.onListItemClick(listView,view,position,id);
Log.e("Item" ,"click"+ position);
procceedToOtherActivity(position);
}
private void procceedToOtherActivity (int position){

NoteStructure note = (NoteStructure) getListAdapter().getItem(position);
Intent intent = new Intent(getActivity().getApplicationContext(),DetailActivity.class);
intent.putExtra(MainActivity.NOTEID,note.getNoteId() );
intent.putExtra(MainActivity.NOTETITLE,note.getTitle());
intent.putExtra(MainActivity.NOTESUMMARY,note.getSummary());
startActivity(intent);
}

这是 Note 适配器:

public class NoteAdapter extends ArrayAdapter<NoteStructure> {

public static class ViewRef {

TextView noteTitle;
TextView noteSummary;
}
public NoteAdapter(Context context, ArrayList<NoteStructure> notes){

super(context,0,notes);
}

public View getView(int position, View convertView, ViewGroup parent){

NoteStructure note = getItem(position);
ViewRef viewRef;
if(convertView==null) {

viewRef = new ViewRef();
convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_list_row,parent,false);
viewRef.noteTitle=(TextView)convertView.findViewById(R.id.noteTitle);
viewRef.noteSummary=(TextView)convertView.findViewById(R.id.noteSummary);
convertView.setTag(viewRef);
}
else {

viewRef = (ViewRef) convertView.getTag();
}



viewRef.noteTitle.setText(note.getTitle());
viewRef.noteSummary.setText(note.getSummary());

return convertView;
}

我还有一个 NoteStructure 类,它只包含 id、title 和 summary 变量以及 getter 和 setter,而 mainActivity 和 DetailActivity 现在什么都不做。我搜索了很多,但我无法弄清楚为什么 DetaiLActivity 没有启动的问题。有人可以帮帮我吗?

这是我使用临时监听器的实现

public class MainListFragment extends Fragment {

private View view;
private ListView list;
private ArrayList<NoteStructure> notes;
private NoteAdapter noteAdapter;
public MainListFragment() {
// Required empty public constructor
}


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

view = inflater.inflate(R.layout.main_fragment_layout, container, false);

list= (ListView) view.findViewById(R.id.listView);
notes = new ArrayList<NoteStructure>();
notes.add(new NoteStructure("malakia", "sdfsfsdfffffffsdfsfsfdfsfsds"));
notes.add(new NoteStructure("sou gamw", "gamithikessssssssssssssssssssssssssssssssss"));

noteAdapter = new NoteAdapter(getActivity(),notes);
list.setAdapter(noteAdapter);

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
procceedToOtherActivity(position);
}
});

return view;
}

private void procceedToOtherActivity (int position){

NoteStructure note = (NoteStructure) list.getAdapter().getItem(position);
Intent intent = new Intent(getActivity().getApplicationContext(),DetailActivity.class);
intent.putExtra(MainActivity.NOTEID,note.getNoteId() );
intent.putExtra(MainActivity.NOTETITLE,note.getTitle());
intent.putExtra(MainActivity.NOTESUMMARY,note.getSummary());
startActivity(intent);
}

最佳答案

您的 itemClickListener 没有触发。您应该像这样覆盖监听器:

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO implement some logic
}

或者你应该扩展普通 fragment

public class MainListFragment extends Fragment{

并为 ListView 创建临时的简单监听器:

listview.setAdapter(noteAdapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
procceedToOtherActivity(position);
}
});

关于android - 点击ListView时出错,D/ViewRootImpl : ViewPostImeInputStage processPointer 0 D/ViewRootImpl: ViewPostImeInputStage processPointer 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43918197/

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