gpt4 book ai didi

java - ListView onItemClickListener 不工作。单击不起作用

转载 作者:行者123 更新时间:2023-11-29 04:46:29 25 4
gpt4 key购买 nike

适配器

package ooad.issuemanagementsystem;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import java.util.ArrayList;

public class ManagerAdapter extends ArrayAdapter<Issue> {
Context c;
int layoutFile;
ArrayList<Issue> data;
public ManagerAdapter(Context context, int resource, ArrayList<Issue> objects) {

super(context, resource, objects);
c = context;
layoutFile = resource;
data = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if(convertView == null)
{
LayoutInflater inflater = ((Activity) c).getLayoutInflater();
row = inflater.inflate(R.layout.manager_row, parent, false);
}
else {
row = (View) convertView;
}
TextView t1 = (TextView) row.findViewById(R.id.textView32);
TextView t2 = (TextView) row.findViewById(R.id.textView31);
t1.setText(data.get(position).getTitle());
t2.setText(data.get(position).getDescription());
CheckBox c = (CheckBox) row.findViewById(R.id.checkBox2);
c.setClickable(false);
if(data.get(position).getOpen().equals("true"))
c.setChecked(false);
else
c.setChecked(true);


return row;
}
}

Activity

package ooad.issuemanagementsystem;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.List;
public class ManagerActivity extends AppCompatActivity {
Context con;
String DeleteObject;
String dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manager);
con = this;
Intent i = getIntent();
dept = i.getStringExtra("dept");
ListView l = (ListView) findViewById(R.id.listView3);
ArrayList<Issue> reports = new ArrayList<Issue>();
reports.add(new Issue("","","","",""));
ManagerAdapter adapter = new ManagerAdapter(this,R.id.listView3,reports);
l.setAdapter(adapter);
l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*Intent i = new Intent(con, IssueDetails.class);
i.putExtra("Title", reports.get(position).getTitle());
i.putExtra("Description", reports.get(position).getDescription());
i.putExtra("Category", reports.get(position).getCategory());
i.putExtra("Id", reports.get(position).getID());
i.putExtra("isOpen", reports.get(position).getOpen());
startActivity(i);*/
Toast.makeText(con, "hi", Toast.LENGTH_LONG).show();
}
});
//String Application_id = "AMavRlzklxFLKZAtEV7OGNyHYI3ByyRnhzhoUwLD";
//String Client_id = "hMSZHpWUsCtKXgtAlmjugpcm2ycqKwYo6lCgWgX1";
//Parse.initialize(c, Application_id, Client_id);
/*ParseQuery<ParseObject> query2 = ParseQuery.getQuery("ISSUES");
query2.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> postList, ParseException e) {
if (e == null) {
for (ParseObject post : postList) {
String a = post.getObjectId();
String b = post.getString("Title");
String c = post.getString("Description");
String d = post.getString("isOpen");
String ee = post.getString("Category");
reports.add(new Issue(a, b, d, c, ee));
adapter.notifyDataSetChanged();
}
} else {
Log.d(getClass().getSimpleName(), "Error: " + e.getMessage());
}
}
});*/

//adapter.notifyDataSetChanged();
/*l.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
DeleteObject = reports.get(position).getID();
reports.remove(position);
adapter.notifyDataSetChanged();
ParseQuery<ParseObject> query3 = ParseQuery.getQuery("ISSUES");
query3.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> postList, ParseException e) {
if (e == null) {
for (ParseObject post : postList) {
String a = post.getObjectId();
String b = post.getString("Title");
String c = post.getString("Description");
String d = post.getString("isOpen");
String ee = post.getString("Category");
if (a.equals(DeleteObject)) {
post.put("isOpen", "false");
post.saveInBackground();
}
}
} else {
Log.d(getClass().getSimpleName(), "Error: " + e.getMessage());
}
}
});
return false;
}
});*/
}
public void generateReport(View v)
{
Intent i = new Intent(con,GenerateReport.class);
i.putExtra("dept1",dept);
startActivity(i);
}
}

我在我的 managerActivity 中勾选了我的 ListView 的点击事件,但它不工作。我还附加了我的自定义适配器。我在 onclick 事件中显示了一个测试 toast,但它不起作用。请帮忙

最佳答案

在适配器 xml 父布局中粘贴行 (android:descendantFocusability="blocksDescendants") 并将 android:focusable="false" 粘贴到复选框或按钮中适配器 xml 文件。

关于java - ListView onItemClickListener 不工作。单击不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36917144/

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