我想让我的列表可以点击并想要开始一个新的活动,但我无法点击,当我点击列表时没有任何反应。 请帮我制作可点击的列表视图。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_user_events);
lists = (ListView) findViewById(R.id.list2);
final QueryClass qc = new QueryClass(getApplication());
qc.open();
EventName = qc.getUserEventName();
eventDate = qc.getUserEventDate();
qc.close();
CustomClass adapter = new CustomClass(this, EventName, eventDate, deleteButton);
lists.setAdapter(adapter);
lists.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(GetUserEvents.this,GetUserFunctions.class);
startActivity(intent);
}
});
}
块引用
答案 0 :(得分:0)
试试这个,它有效:
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
startActivity(new Intent(GetUserEvents.this,GetUserFunctions.class));
}
});
答案 1 :(得分:0)
这是我完整的课程。
package weddingplanner.countmyapp.com.weddingplanner;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class GetUserEvents extends Activity {
ListView lists;
ArrayList<String> EventName = new ArrayList<>();
ArrayList<String> eventDate = new ArrayList<>();
ArrayList<String> deleteButton = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_user_events);
lists = (ListView) findViewById(R.id.list2);
final QueryClass qc = new QueryClass(getApplication());
qc.open();
EventName = qc.getUserEventName();
eventDate = qc.getUserEventDate();
qc.close();
CustomClass adapter = new CustomClass(this, EventName, eventDate, deleteButton);
lists.setAdapter(adapter);
lists.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(GetUserEvents.this,GetUserFunctions.class);
startActivity(intent);
}
});
}
}
块引用