我有这个代码来捕获图像并在ListView中显示它 点击列表项目,我可以捕获图像并保存到图像视图,但如何在列表项的左侧进行操作?
public class ShootList extends ListActivity implements OnItemClickListener {
String[] listItems = {"HeadShot", "BodyShot ", "ExtraShot", "Video Take1", "Video Take2", "Video Take3", };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, listItems));
ListView shot = getListView();
shot.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int Position, long arg3) {
// TODO Auto-generated method stub
int P = Position;
switch ( P ) {
case 0:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 1);
break;
case 1:
AlertDialog.Builder alertbox1 = new AlertDialog.Builder(this);
alertbox1.setMessage("BodyShot").show();
break;
case 2:
AlertDialog.Builder alertbox2 = new AlertDialog.Builder(this);
alertbox2.setMessage("ExtraShot").show();
break;
case 3:
Intent Take1 = new Intent("android.media.action.VIDEO_CAPTURE");
startActivityForResult(Take1, 0);
break;
case 4:
AlertDialog.Builder alertbox4 = new AlertDialog.Builder(this);
alertbox4.setMessage("Take2").show();
break;
case 5:
AlertDialog.Builder alertbox5 = new AlertDialog.Builder(this);
alertbox5.setMessage("Take3").show();
break;
default:
break;
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
int i;
// if Activity was canceled, display a Toast message
if (resultCode == RESULT_CANCELED) {
Toast toast = Toast.makeText(this,"camera cancelled", 10000);
toast.show();
return;
}
// lets check if we are really dealing with a picture
if (requestCode == 1 && resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
//setContentView(R.layout.main);
ImageView mImg;
mImg = (ImageView) findViewById(R.id.img);
mImg.setImageBitmap(b);
// save image to gallery
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
}
}
}
答案 0 :(得分:2)
注意:您应该始终包含对问题的解释,而不仅仅是代码。
如果你想要一个包含列表项的图标,那么你需要将它包含在列表项的布局xml文件中,它看起来像这样:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@-id/image />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@-id/text" />
</LinearLayout>
然后,您需要创建自定义list adapter并覆盖getView()方法以设置图像和文本字段。对于您的所有列表视图需求,请转到here
答案 1 :(得分:0)
最简单的方法是直接在XML布局文件中使用TextView的android:drawableRight
或android:drawableLeft
属性。
否则您可以使用RelativeLayout,请参阅this blog post。
答案 2 :(得分:0)
使用具有TextView和ImageView的列表项高效实现Custom ListView