我使用这个框架,我已经尝试了很多次来解决这个问题,但我不能这样做。我已经问过stackoverflow但没有人不能帮助我。其实我试过了。
我正在使用这个框架:https://github.com/kikoso/Swipeable-Cards
我正在使用SimpleCardStackAdapter:
for (int i = 0; i < user.length(); i++) {
final JSONObject c = user.getJSONObject(i);
// Storing JSON item in a Variable
String id = c.getString(user_id);
String name = c.getString(username);
final String email = c.getString(text);
String image1 = c.getString(imageUrl);
String range1 = c.getString(range);
String msgId = c.getString(postId);
// adapter.add(new CardModel(name, email, image1));
//Set JSON Data in TextView
Log.i("image1image1image1image1", image1);
// CardModel cardModel = new CardModel(" cardModel", " CardModel", r.getDrawable(R.drawable.picture1));
card = new CardModel(name, email, image1);
card.setOnClickListener(new CardModel.OnClickListener() {
@Override
public void OnClickListener() {
Log.i("Swipeable Cards", "I am pressing the card");
// Intent no = new Intent(HomeListview.this, YayDetailActivity.class);
/// startActivity(no);
}
});
card.setOnCardDimissedListener(new CardModel.OnCardDimissedListener() {
@Override
public void onLike(CardModel card) {
Log.i("Swipeable Cards", "I dislike the card");
}
@Override
public void onDislike(CardModel card) {
Log.i("Swipeable Cards", "I like the card");
// new sendNewYay().execute(sharedToken, card.getTitle());
Toast.makeText(getApplicationContext(), card.getDescription(), Toast.LENGTH_SHORT).show();
}
});
// I m added adapter
adapter.add(card);
mCardContainer.setAdapter(adapter);
}
在onDislike方法中,我需要获取项目名称。
在这一行:new sendNewYay()。execute(sharedToken,name);
我发送了项目名称,但它不起作用。
1.如何在此方法中获取项目名称? 2.我有两个按钮,其中一个用于onLike方法,另一个用于onDislike方法。我可以用我的按钮触发这两种方法吗?
谢谢。
答案 0 :(得分:0)
将两个变量全局解析为字符串
String itemname;
try {
JSONArray c = new JSONArray(user.toString());
for (int i = 0 ; i < c.length();i++) {
String id = c.getString(user_id);
String name = c.getString(username);
final String email = c.getString(text);
String image1 = c.getString(imageUrl);
String range1 = c.getString(range);
String msgId = c.getString(postId);
System.out.println("Position : " + "" + i + ""+ c.getString(i));
itemname = name.getString(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("Final itemname is " + itemname);