单击它后,我必须更改 textView。我尝试通过 android:onclick 执行此操作,但它不起作用,然后我尝试执行此操作,但仍然出现错误。
这是我的适配器代码:
package howcomment;
import java.util.Collections;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.logintest.R;
import dataBase.DataBaseHandler;
import functions.Methods;
public class CustomeAdapterHowComment extends ArrayAdapter<ItemsHowComment>{
Context context;
ItemsHowComment items;
List<ItemsHowComment> Items1;
Bitmap bitmap;
String imageUser = "";
String filePath_Image = "/Pictures/jehad/joj/";
String user_id = "1002";
String secret_id = "2143054018";
int x;
String table = "10";
String target = "";
DataBaseHandler dbobj;
public static String server_List_of_Comments = "https://www.ashabe.com/";
public static String server_Comment_like = "https://www.ashabe.com";
public static String server_Comment_like_remove = "https://www.ashabe.com/";
String response;
public CustomeAdapterHowComment(Context context,
int textViewResourceId, List<ItemsHowComment> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
this.context=context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
Log.d("View ", "View>>>>>>>>");
commentholder h = null;
View v = convertView;
items = getItem(position);
LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
v = vi.inflate(R.layout.how_comment_list,null);
h = new commentholder();
h.img=(ImageView)v.findViewById(R.id.commentimg);
h.name=(TextView)v.findViewById(R.id.commentname);
h.commentBody=(TextView)v.findViewById(R.id.commentbody);
h.like=(TextView)v.findViewById(R.id.commentlike);
h.numoflike=(TextView)v.findViewById(R.id.commentnumoflike);
v.setTag(h);
} else {
h = (commentholder)v.getTag();
}
imageUser = items.getUserId() + items.getRand();
boolean flag_ImagePath = Methods.checkIfImage_DirExists(filePath_Image
+ imageUser);
if (flag_ImagePath == true) {
Log.v("flag_ImagePath", String.valueOf(flag_ImagePath));
bitmap = Methods.displayBitmapImage(imageUser);
h.img.setImageBitmap(bitmap);
}
h.commentBody.setText(items.getCommentBody());
h.name.setText(items.getName());
if(items.getiLike().equals("0")){
h.like.setText("Like");
}if (items.getiLike().equals("1")) {
h.like.setText("Unlike");
}
if(items.getNumOfLike().equals("0")){
h.numoflike.setText("");
}else{
h.numoflike.setText(items.getNumOfLike());
}
这是 textview onclick 它工作正常,但 onItemclick dosnt 工作
v.setTag(R.id.CommentLike, h.like);
h.like.setTag(position);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView like =(TextView)v.getTag(R.id.CommentLike);
TextView numoflike =(TextView)v.getTag(R.id.CommentNumOfLike);
x =(Integer)like.getTag();
// Toast.makeText(getContext(), "like"+like.getTag(position).toString(), Toast.LENGTH_SHORT).show();
dbobj = new DataBaseHandler(getContext());
Items1=dbobj.select_Howliketest();
dbobj.CloseDataBase();
Collections.reverse(Items1);
target=Items1.get(x).getCommentId().toString();
CommentEvents r=new CommentEvents();
r.execute(user_id,secret_id,table,target);
if(Items1.get(x).getiLike().equals("0")){
like.setText("Unlike");
}else if (Items1.get(x).getiLike().equals("1")) {
like.setText("Like");
}
}
});
return v;
}
这是我的 AsyncTask
class CommentEvents extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
dbobj = new DataBaseHandler(getContext());
Items1=dbobj.select_Howliketest();
dbobj.CloseDataBase();
Collections.reverse(Items1);
Log.e("ffffff", (Items1.get(x).getiLike().toString()));
if(Items1.get(x).getiLike().toString().equals("0")){
response=Methods.HTTP_CommentLike(server_Comment_like, table, target, user_id, secret_id);
}else {
response=Methods.HTTP_CommentLike(server_Comment_like_remove, table, target, user_id, secret_id);
}
dbobj=new DataBaseHandler(getContext());
dbobj.delete_Comment_TABLE();
dbobj.CloseDataBase();
response = Methods.HTTP_CommentList(server_List_of_Comments, "5",
"6462", user_id, secret_id);
response = "{" + response + "}";
Methods.install_JSON_HowComment(getContext(), response);
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
}
这是我的持有人
class commentholder {
ImageView img;
TextView name;
TextView commentBody;
TextView like,numoflike;
}
在我的活动中,单击该项目时它不起作用,我的文本视图工作而不是单击项目
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.v("pos", "click");
}
});