I implemented a listview in one of the fragments. How do I code to make another activity appear when I click? I'm a beginner. Please help me.
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
}
}) ;
If you put this in and use it, the method is different from the one in the fragment, so there is an error... Help me
android listview fragment
Read the comments and add more content.
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
adapterView.getItemAtPosition(pos);
// You can import items that you clicked on in this way. I don't know what kind of data structure the item was made in the list view, but you can bring the item, check it, and make a branch with an if statement or case clause to call the activity.
}
You can just write the code you wrote down. Take a listview in the Fragment, attach setOnItemClickListener to the listview, and in the onItemClick function
Intentint=newIntent(getActivity(), the activity you want to invoke.class);
startActivity(intent);
You can do it. If you show me the error log, I can see what the problem is.
public class SocialFragment extends Fragment {
Static final String[] LIST_MENU = {"★"Club List2", "Club List3", "Club List4", "Club List5", ★ Literature-related Division", "Club List8", "Club List9", "Club List10", "★", "Club List13", "Club List12"
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.social_layout, null);
ArrayAdapter Adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, LIST_MENU);
ListView listview = (ListView) view.findViewById(R.id.listView);
listview.setAdapter(Adapter);
return view;
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
adapterView.getItemAtPosition(pos);
if (LIST_MENU == null) {
Intent intent = new Intent(getActivity(), List1.class);
startActivity(intent);
}
}
If you write }; //this part), an error appears under the red underline. Please solve this, too.
}
}
It's coded like this. I'm not sure how to use that if clause over there. I want a new activity window to appear when I click on the list of club list 1 and club list 2 up there. I'd appreciate your help.
581 PHP ssh2_scp_send fails to send files as intended
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.