m0_58809419
2022-04-06 10:24
采纳率: 33.3%
浏览 39

Android studio真机运行测试app闪退,



```xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <ImageView
        android:id="@+id/iv"
        android:layout_width="120dp"
        android:layout_height="90dp"
        android:layout_centerVertical="true" />
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/iv"A
        android:layout_centerVertical="true"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="花椒"
        android:textColor="#000000"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>


```java
public class MainActivity extends AppCompatActivity {
    private ListView mListView;
    private String titles []={"花椒","红苹果","桃花李","野果子","樱桃"};
    private String prices []={"128/斤","12/斤","15/斤","23/斤","30/斤"};
    private int icons []={R.drawable.hj,R.drawable.hpg,R.drawable.thl,R.drawable.per,R.drawable.yt};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adapter);
        mListView=findViewById(R.id.lv);
        MyBaseAdapter myBaseAdapter=new MyBaseAdapter();
        mListView.setAdapter(myBaseAdapter);
    }
    class MyBaseAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int position) {
            return titles[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view=View.inflate(MainActivity.this,R.layout.adapter,null);
            TextView title=view.findViewById(R.id.title);
            TextView price=view.findViewById(R.id.price);
            ImageView icon=view.findViewById(R.id.iv);
            title.setText(titles[position]);
            price.setText(prices[position]);
            icon.setBackgroundResource(icons[position]);
            return view;
        }
    }
}

log日志找不到

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题