1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| package com.example.menu;
import java.util.ArrayList;
import java.util.HashMap;
import com.example.menu.actionBar.OnDispatchClickListener;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class listImage extends Activity implements OnDispatchClickListener{
final String EXTRA_LOGIN = "user_login";
EditText login;
private Button b1;
private actionBar abar;
private TextView textView;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ouvrir);
login = (EditText)findViewById(R.id.edit);
abar = (actionBar)findViewById(R.id.actionbar);
abar.setTitle("Information");
abar.showButtonSearch();
abar.showButtonComment();
abar.setOnDispatchClickListener(this);
textView= (TextView)findViewById(R.id.click);
listView = (ListView)findViewById(R.id.listviewperso);
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
map = new HashMap<String, String>();
map.put("titre", "Coupe1");
map.put("description", "coupe1");
map.put("img", String.valueOf(R.drawable.coupe1));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "coupe2");
map.put("description", "coupe2");
map.put("img", String.valueOf(R.drawable.coupe2));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "coupe3");
map.put("description", "coupe3");
map.put("img", String.valueOf(R.drawable.coupe3));
listItem.add(map);
SimpleAdapter mAdapter = new SimpleAdapter(this.getBaseContext(), listItem, R.layout.affichageitem, new String[] {"img", "title", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
listView.setAdapter(mAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
HashMap<String, String>map=(HashMap<String, String>)listView.getItemAtPosition(position);
Intent intent = new Intent (listImage.this, image.class);
startActivity(intent);
}
});
b1 = (Button)findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(listImage.this, image.class);
intent.putExtra(EXTRA_LOGIN, login.getText().toString());
startActivity(intent);
}
});
}
@Override
public void onDispatchClick(int id) {
switch (id)
{
case R.id.ab_home:
textView.setText("Home");
break;
case R.id.ab_comment:
textView.setText("Informations");
break;
case R.id.ab_search:
textView.setText("Recherche");
break;
}
}
} |
Partager