我是 android 的新手。我正在使用包含图像和 textview 的列表视图。我想在每一行中添加箭头图标。我正在尝试但我无法做到这一点。我该怎么做?代码如下。非常感谢任何帮助。
CategoryActivity.java
public class CategoryActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.category1);
ImageView in1 = (ImageView) findViewById(R.id.glrrr1);
in1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),ImageSwitcherA.class);
startActivityForResult(myIntent, 0);
}
});
ImageView in2 = (ImageView) findViewById(R.id.grid1);
in2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent1 = new Intent(view.getContext(),RingGridView.class);
startActivityForResult(myIntent1, 0);
}
});
ListView view = (ListView) findViewById(R.id.list);
//instance of custom adapter
view.setAdapter(new CustomImageListAapter(this));
view.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Intent i = new Intent(AndroidGridLayoutActivity.this,FullImageActivity.class);
//Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
//i.putExtras(bundle);
//startActivity(i);
if(position ==0)
{
Intent ii = new Intent(CategoryActivity.this,Ring1Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
ii.putExtra("operation", position);
startActivity(ii);
}
if(position ==1)
{
Intent in = new Intent(CategoryActivity.this,Ring2Full.class);
//Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
in.putExtra("operation", position);
startActivity(in);
}
if(position ==2)
{
Intent inn = new Intent(CategoryActivity.this,Ring3Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
inn.putExtra("operation", position);
startActivity(inn);
}
if(position ==3)
{
Intent innm = new Intent(CategoryActivity.this,Ring4Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
innm.putExtra("operation", position);
startActivity(innm);
}
if(position ==4)
{
Intent intt = new Intent(CategoryActivity.this,Ring5Full.class);
//Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
intt.putExtra("operation", position);
startActivity(intt);
}
if(position ==5)
{
Intent intt5 = new Intent(CategoryActivity.this,Ring6Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
intt5.putExtra("operation", position);
startActivity(intt5);
}
if(position == 6)
{
Intent buset= new Intent(CategoryActivity.this,Ring7Full.class);
// Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
buset.putExtra("operation", position);
startActivity(buset);
}
if(position == 7)
{
Intent buses= new Intent(CategoryActivity.this,Ring8Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
buses.putExtra("operation", position);
startActivity(buses);
}
if(position == 8)
{
Intent busez= new Intent(CategoryActivity.this,Ring9Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busez.putExtra("operation", position);
startActivity(busez);
}
if(position == 9)
{
Intent buseh= new Intent(CategoryActivity.this,Ring10Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
buseh.putExtra("operation", position);
startActivity(buseh);
}
if(position == 10)
{
Intent busek1= new Intent(CategoryActivity.this,Ring11Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busek1.putExtra("operation", position);
startActivity(busek1);
}
if(position == 11)
{
Intent busek2= new Intent(CategoryActivity.this,Ring12Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busek2.putExtra("operation", position);
startActivity(busek2);
}
if(position == 12)
{
Intent busek3= new Intent(CategoryActivity.this,Ring13Full.class);
//Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
busek3.putExtra("operation", position);
startActivity(busek3);
}
if(position == 13)
{
Intent busek4= new Intent(CategoryActivity.this,Ring14Full.class);
//Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
busek4.putExtra("operation", position);
startActivity(busek4);
}
if(position == 14)
{
Intent busek5= new Intent(CategoryActivity.this,Ring16Full.class);
// Bundle bundle = new Bundle();
// bundle.putInt("operation", position);
busek5.putExtra("operation", position);
startActivity(busek5);
}
if(position == 15)
{
Intent busek6= new Intent(CategoryActivity.this,Ring16Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busek6.putExtra("operation", position);
startActivity(busek6);
}
if(position == 16)
{
Intent busek7= new Intent(CategoryActivity.this,Ring17Full.class);
// Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busek7.putExtra("operation", position);
startActivity(busek7);
}
if(position == 17)
{
Intent busek8= new Intent(CategoryActivity.this,Ring18Full.class);
//Bundle bundle = new Bundle();
//bundle.putInt("operation", position);
busek8.putExtra("operation", position);
startActivity(busek8);
}
}
});}}
CustomImageListAapter.java
public class CustomImageListAapter extends BaseAdapter {
private int[] images = {
R.drawable.rrr1,
R.drawable.rrr2,
R.drawable.rrr3,
R.drawable.rrr4,
R.drawable.rrr5,
R.drawable.rrr6,
R.drawable.rrr7,
R.drawable.rrr8,
R.drawable.rrr18,
R.drawable.rrr10,
R.drawable.rrr11,
R.drawable.rrr12,
R.drawable.rrr13,
R.drawable.rrr14,
R.drawable.rrr15,
R.drawable.rrr16,
R.drawable.rrr17,
R.drawable.rrr18,
};
private String[] imageDesc = { "Diamond Ring", "Silver Ring",
"Gold Ring","Antique Ring","Pearl Ring","Beats Ring","Diamond Ring","Stone Ring","Antique Ring","Diamond Ring", "Silver Ring",
"Gold Ring","Antique Ring","Pearl Ring","Beats Ring","Diamond Ring","Stone Ring","Antique Ring"};
Context ctx = null;
public CustomImageListAapter(Context context) {
this.ctx = context;
}
public int getCount() {
return images.length;
}
public Object getItem(int arg0) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView imgView = new ImageView(this.ctx);
imgView.setScaleType(ScaleType.FIT_CENTER);
imgView.setPadding(8, 8, 8, 8);
imgView.setImageResource(images[arg0]);
imgView.setAdjustViewBounds(Boolean.TRUE);
imgView.setContentDescription(imageDesc[arg0]);
imgView.setMaxHeight(200);
imgView.setMaxWidth(200);
TextView tv = new TextView(this.ctx);
tv.setText(imageDesc[arg0]);
tv.setMaxHeight(100);
tv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tv.setGravity(Gravity.CENTER);
LinearLayout layoutView = new LinearLayout(this.ctx);
layoutView.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(150, 150);
layoutView.addView(imgView, params1);
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
layoutView.addView(tv, params2);
return layoutView;
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/background"
android:gravity="center_vertical"
android:orientation="vertical" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/list"
android:background="@drawable/bkg">
</ListView>
</LinearLayout>