N
N
nikita_chiru2016-06-29 23:31:42
Android
nikita_chiru, 2016-06-29 23:31:42

How to get the test from the list in my example?

you need to set 3 value to throw them into the database.
tell me how to count?

public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    private SwipeLayoutAdapter mAdapter;
    private ListView mListView;
    private List<ListData> mData;
    private static int mCurrentIndex;
    private GridView mGridView;
    DBHelper dbHelper;
    TextView tv;
    TextView textView2;


    public void insertData(int n)
    {
        for(int i = 0 ; i < n; i++)
        {
            mData.add(new ListData("hello ",299,R.drawable.alkap ));
            mData.add(new ListData("карка " ,9,R.drawable.dakota ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.saiman ));
            mData.add(new ListData("лалка " ,99,R.drawable.dragon ));
            mData.add(new ListData("лалка " ,99,R.drawable.yasai ));
            mData.add(new ListData("лалка " ,99,R.drawable.california ));
            mData.add(new ListData("лалка " ,99,R.drawable.california ));
            mData.add(new ListData("лалка " ,99,R.drawable.kaisen));
            mData.add(new ListData("лалка " ,99,R.drawable.slivslos ));
            mData.add(new ListData("лалка " ,99,R.drawable.raduga ));
            mData.add(new ListData("лалка " ,199,R.drawable.dvoi ));
        }
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        mData = new ArrayList<>();
        insertData(1);
        mCurrentIndex = 0;
        mListView = (ListView)findViewById(R.id.listView);
        mGridView = (GridView)findViewById(R.id.gridview);
        mAdapter = new MyAdapater(this,R.layout.item_content,R.layout.item_action,mData);
        //mGridView.setAdapter(mAdapter);
        //如果要使用GridView,只需要注释掉mListView.setAdapter(mAdapter);去掉上方的注释
        mListView.setAdapter(mAdapter);


    }


    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_camera) {
            // Handle the camera action
        } else if (id == R.id.nav_gallery) {

        } else if (id == R.id.nav_slideshow) {

        } else if (id == R.id.nav_manage) {

        } else if (id == R.id.nav_share) {

        } else if (id == R.id.nav_send) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
    class MyAdapater extends SwipeLayoutAdapter<ListData>
    {
        private List<ListData> _data;
        public MyAdapater(Activity context, int contentViewResourceId, int actionViewResourceId, List<ListData> objects)
        {
            super(context,contentViewResourceId,actionViewResourceId,objects);
            _data = objects;
        }

        //实现setContentView方法
        @Override
        public void setContentView(View contentView, int position, HorizontalScrollView parent) {
            ListData p=((ListData) getItem(position));
            TextView tv = (TextView)contentView.findViewById(R.id.textView2);
            tv.setText(p.price+"руб");
            TextView tv1 = (TextView)contentView.findViewById(R.id.tv);
            tv1.setText(p.title);
            ImageView tv3 = (ImageView) contentView.findViewById(R.id.imageView1);
            tv3.setImageResource(p.image);
        }

        //实现setActionView方法
        @Override
        public void setActionView(final View contentView, final int position, final HorizontalScrollView parent) {



            final String value3 = MyAdapater.getItem(position).title;



            contentView.findViewById(R.id.action).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), "Action 2 for " +"цена"+ value3, Toast.LENGTH_SHORT ).show();




                }
            });

            contentView.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"star item - " + position,Toast.LENGTH_SHORT).show();
                }
            });

        }


    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nikita_chiru, 2016-06-30
@nikita_chiru

ListData p=((ListData) getItem(position));

            final String value3 = p.title;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question