I am somewhat of a beginner to Android (somewhat), and I am having a problem adapting code to my use. I've gotten everything except the if statement. Which is sad, because that's a rather basic thing.
I'm parsing a JSON file, and outputting it's results into a ListView using a Hashmap. So far, so good. I want to put an AlertDialog as one of the String "put"s of the Hashmap. Fine.
However, I now want to check that if the title (which is in the map) ends in ".pdf", to do a different action rather than displaying the AlertDialog.
Code:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { HashMap<String, String> item = (HashMap<String, String>)
parent.getItemAtPosition(position);
String theTitle = item.get("title");
String theDesc = item.get("description");
String theLink = item.get("link");
if (???condition???) {
//code I already have
} else {
final AlertDialog.Builder hope = new AlertDialog.Builder(MainActivity.this);
hope.setTitle("Description");
hope.setMessage(theDesc);
hope.setPositiveButton("DISMISS",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}});
hope.setNegativeButton("",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}});
hope.show();
}
Any, and all, help would be most appreciated!
Aucun commentaire:
Enregistrer un commentaire