Android studio 将listview转换为具有自定义行的listview

Android studio 将listview转换为具有自定义行的listview,android-studio,android-listview,Android Studio,Android Listview,我正在尝试将基本列表视图转换为复杂列表视图。我尝试通过创建一个产品适配器来实现这一点。我一直在超级部分上看到一个错误,说“objects中的objects()无法应用”。我以前没有这样做过,我是按照一个教程 public class ProductAdapter { ProductAdapter(Context context, String[] addProduct){ super(context,R.layout.list_item, addProduct); } @Overrid

我正在尝试将基本列表视图转换为复杂列表视图。我尝试通过创建一个产品适配器来实现这一点。我一直在超级部分上看到一个错误,说“objects中的objects()无法应用”。我以前没有这样做过,我是按照一个教程

public class ProductAdapter {

ProductAdapter(Context context, String[] addProduct){
    super(context,R.layout.list_item, addProduct);
}
@Override
public View getView(int position,View convertView, ViewGroup parent){
    LayoutInflater momentsInflater = LayoutInflater.from(getContext());
    View customView = momentsInflater.inflate(R.layout.list_item, parent, false);

    ImageView imageView = (ImageView) customView.findViewById(R.id.imageView);
    TextView momentsText = (TextView) customView.findViewById(R.id.textViewName);
    ImageView momentsImage = (ImageView) customView.findViewById(R.id.imageView);



    }
};
主要活动

public class MainActivity extends Activity {
    private ListView listView;
    private String[] details;
    public static ArrayList<Product> product = new ArrayList<>();
    boolean firstRun = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.listView);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.action_AddProduct:
                startActivity(new Intent(MainActivity.this, Activity_addProduct.class));

            case R.id.action_Information:
                startActivity(new Intent(MainActivity.this, Activity_addProduct.class));
                return true;
            case R.id.action_Home:

                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        DatabaseHandler db = new DatabaseHandler(this);
        String[] productStrings;
        if (firstRun) {
            String[] placeHolterStrings = {"", ""};
            productStrings = placeHolterStrings;
            firstRun = false;
        } else {
            product = db.getAllContacts();
            productStrings = new String [product.size()];

            for (int i = 0; i < product.size(); i++) {
                productStrings[i] = product.get(i).toString();
            }
        }

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, productStrings);
        listView.setAdapter(arrayAdapter);
        listView.setOnItemClickListener(

                new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    }
                }
        );
    }
}
List_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:background="@android:color/darker_gray"
        android:padding="8dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:scaleType="centerCrop" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textViewName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="first + last name"
            android:textSize="16dp" />

        <TextView
            android:id="@+id/textViewDetail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="details of the candidate"
            android:textSize="12dp" />

    </LinearLayout>

</LinearLayout>

复杂列表视图如下所示:


@FrankN.Stein我在下面贴了一张图片。这并不复杂,但我认为这是它的正式名称。是的,它只是一个使用图像和文本视图的列表视图。@FrankN.Stein谢谢!我在看youtube视频,他们就是这么叫的。我确定了标题。希望你能帮忙!好。。。我会在另一个布局中创建您的自定义项(RelativeLayout中有1个ImageView和2个TextView)。然后使用ViewHolder填充每个项目,因为这样更快。但是如果你想要最快的东西,你应该切换到一个持有CardView的RecyclerView。至少,他们说这是目前可用的最快的东西。@FrankN.Stein我在下面贴了一张图片。这并不复杂,但我认为这是它的正式名称。是的,它只是一个使用图像和文本视图的列表视图。@FrankN.Stein谢谢!我在看youtube视频,他们就是这么叫的。我确定了标题。希望你能帮忙!好。。。我会在另一个布局中创建您的自定义项(RelativeLayout中有1个ImageView和2个TextView)。然后使用ViewHolder填充每个项目,因为这样更快。但是如果你想要最快的东西,你应该切换到一个持有CardView的RecyclerView。至少,他们说这是目前可用的最快的东西。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:background="@android:color/darker_gray"
        android:padding="8dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:scaleType="centerCrop" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textViewName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="first + last name"
            android:textSize="16dp" />

        <TextView
            android:id="@+id/textViewDetail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:text="details of the candidate"
            android:textSize="12dp" />

    </LinearLayout>

</LinearLayout>