이미지와 텍스트가 포함 된 목록보기가 있으며 갤러리 의도 onClick을 호출 할 수 있습니다. 여기 이미지를 의도에서 목록보기로 설정하십시오.
내 사용자 지정 행 IH :<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:src="@drawable/ic_launcher" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label" >
</TextView>
</LinearLayout>
및 주요 코드 :
내가 클릭 한 목록 항목의 이미지 뷰에 이미지를 선택 설정하는 방법public class MyActivity extends ListActivity {
private ListView lv;
private ArrayList<String> itemArray;
private ArrayAdapter<String> itemAdapter;
//new gallery intent privates
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
itemArray = new ArrayList<String>();
itemArray.clear();
itemAdapter = new ArrayAdapter<String>(this, R.layout.row, R.id.label, itemArray);
setListAdapter(itemAdapter);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
Toast.makeText(this, selectedImagePath, Toast.LENGTH_SHORT).show();
}
}
}
public String getPath(Uri uri) {
if(uri == null) {
return null;
}
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor != null){
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
return uri.getPath();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
}
protected void addItemList() {
// TODO Auto-generated method stub
itemArray.add(0,"step");
itemAdapter.notifyDataSetChanged();
}
// menu options
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add("add");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
addItemList();
Toast.makeText(this, "test", Toast.LENGTH_SHORT).show();
return super.onOptionsItemSelected(item);
}
}
? 어떤 방법으로도 그들을 연결하는 방법을 찾을 수 없습니다/ (나는 dirrectory를 알고 있다면 이미지를로드하는 방법을 알고 있지만 여기에는 그럴 필요가 없습니다).
을 설정지고 ?? – Sree
선택한 imege를 row.xml의 ImageView로 설정해야합니다. 그 전에 @ drawable/ic_launcher가 있습니다. – user1835337