ボタン「Shortlist」からなるListView
があります。誰かがそのボタンをクリックするとボタンのテキストを変更する必要があります。 Button Shortlistインフレ。ここで、shortlist [position] .toString()値はサーバーから来ており、ボタンのテキストがショートリストされている場合はボタンに表示され、ボタンは押されません。ボタンのテキストがショートリストの場合は、ショートリストとしてボタンに表示され、ボタンを押す必要があります。ListViewでボタンをクリックすると1つの問題が発生する
以下はmyコードです。
public class Profile_Match_custom_List extends ArrayAdapter<String> {
private static final String url ="http://10.0.2.2/xp/shortlist1.php";
private static final String url1 = "http://10.0.2.2/xp/express_intrest.php";
private static final String KEY_MATRI_ID_TO="matriID_to";
private static final String KEY_MATRI_ID_BY="matriID_by";
SessionManager session;
public String matri_id_to, matri_id_by, str_gender;
String str;
public Button btnSort;
private NetworkImageView imageView;
private ImageLoader imageLoader;
private final String[] ids;
private String[] ages;
private String[] heights;
public String[] communities;
public String[] castes;
public String[] educations;
public String[] occupations;
public String[] incomes;
public String[] pics;
public String[] locations;
public String[] shortlist;
public String[] expressinterest;
private Activity context;
public Profile_Match_custom_List(Activity context, String[] ids, String[] ages,
String[] heights, String[] communities, String[] castes,
String[] educations, String[] occupations, String[]incomes,
String[]pics, String[] locations, String[] shortlist, String[] expressinterest) {
super(context, R.layout.custom_profile_match,ids);
this.ids = ids;
this.ages = ages;
this.heights = heights;
this.communities = communities;
this.castes = castes;
this.educations = educations;
this.occupations = occupations;
this.incomes = incomes;
this.pics = pics;
this.locations = locations;
this.shortlist = shortlist;
this.expressinterest = expressinterest;
this.context = context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
final View listViewItem = inflater.inflate(R.layout.custom_profile_match, null, true);
// Session class instance
session = new SessionManager(getContext());
session.checkLogin();
// get user data from session
HashMap<String, String> user = session.getUserDetails();
matri_id_by = user.get(SessionManager.KEY_EMAIL);
str_gender = user.get(SessionManager.KEY_GENDER);
String url1 = "https://www.maangal.com/thumb/thumb_";
String url = url1 + pics[position];
imageView = (NetworkImageView) listViewItem.findViewById(R.id.offer_image);
imageLoader = CustomVolleyRequest.getInstance(this.getContext()).getImageLoader();
if(str_gender.equals("Male")) {
imageLoader.get(url, ImageLoader.getImageListener(imageView, R.drawable.image, R.drawable.girl));
}
else {
imageLoader.get(url, ImageLoader.getImageListener(imageView, R.drawable.image, R.drawable.boy));
}
imageView.setImageUrl(url,imageLoader);
TextView textViewId = (TextView) listViewItem.findViewById(R.id.textViewId);
TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
textViewId.setText(ids[position]);
textViewName.setText(ages[position]+" years"+" , "+heights[position]+" cm"+", "+communities[position]+" : "+castes[position]+" , "+educations[position]+" , "+occupations[position]+" , "+incomes[position]+", "+locations[position]);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(), BlankActivity.class);
Toast.makeText(getContext(), ids[position], Toast.LENGTH_LONG).show();
i.putExtra("id", ids[position]);
v.getContext().startActivity(i);
}
});
/*Button Shortlist inflation, where the shortlist[position].toString()
value comes from server and if the button text is shortlisted then it
will shown on button and button will not pressed. If the button text is
shortlist then it will show on button as shortlist and button should be
pressed.*/
btnSort =(Button) listViewItem.findViewById(R.id.btnshort);
str = shortlist[position].toString();
Log.e("------shortlisted------",str);
if(str.equalsIgnoreCase("shortlisted")) {
btnSort.setText(str);
btnSort.setBackgroundColor(Color.parseColor("#FF307668"));
btnSort.setEnabled(false);
}
else
{
btnSort.setText(str);
}
btnSort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
matri_id_to=ids[position];
shortlist();
}
});
Button btnChat =(Button) listViewItem.findViewById(R.id.btnchat);
btnChat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
matri_id_to=ids[position];
Toast.makeText(getContext(),"sent express intrest",Toast.LENGTH_LONG).show();
express_Intrest();
}
});
Button declineButton = (Button)listViewItem.findViewById(R.id.declineButton);
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return listViewItem;
}
//shortlist method.
private void shortlist(){
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String> () {
@Override
public void onResponse(String response) {
Log.e("***short response----",response.trim());
if(response.trim().equalsIgnoreCase("success")) {
btnSort.setBackgroundColor(Color.parseColor("#FF307668"));
btnSort.setText("shortlisted");
Toast.makeText(getContext(), "shortlisted", Toast.LENGTH_LONG).show();
btnSort.setEnabled(false);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_MATRI_ID_BY,matri_id_by);
params.put(KEY_MATRI_ID_TO,matri_id_to);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
}
public void express_Intrest(){
StringRequest stringRequest1 = new StringRequest(Request.Method.POST, url1, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("response",response);
Toast.makeText(getContext(), response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_MATRI_ID_BY,matri_id_by);
params.put(KEY_MATRI_ID_TO,matri_id_to);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest1);
}
}
は 'btnSort.setBackgroundColor(Color.parseColor("#FF307668 "));'動作しますか?ログの他のエラー? – Vikrant
ボタンをパラメータとしてショートリストに渡して同じことをすることはできますか?それはうまくいくはずです。私はあなたがリストビューのアダプタからこれをやっていると思います... –
完全なコードを表示します。 –