如何从上一页检索信息?

时间:2015-11-16 04:28:31

标签: java android

我的上一页(第2页)看起来像这样

  • 描述
  • 可用尺寸
  • 原产国
  • 鞋模型
  • 价格

我的第3页看起来像这样

  • 名称:
  • 电话号码:
  • 电子邮件:
  • 产品:
  • 费率设计:

我的问题是如何获取鞋子模型的结果(从第2页开始)并将其显示在第3页产品上?对于这两个页面,我有不同的数据库

代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_rbar);

        lvInfo = (ListView) findViewById(R.id.listView);
        txtName = (EditText) findViewById(R.id.editText);
        txtPhone = (EditText) findViewById(R.id.editText3);
        txtEmail = (EditText) findViewById(R.id.editText4);
        txtProduct = (EditText) findViewById(R.id.editText5);
        ratingBar = (RatingBar) findViewById(R.id.ratingBar);


        db = new Database_rbar(this);
        dbAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, ArrayofName);
        lvInfo.setAdapter(dbAdapter);



        lvInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                currentId = results.get(position).getId();
                txtName.setText(results.get(position).getName());
                txtPhone.setText(results.get(position).getPhone());
                txtEmail.setText(results.get(position).getEmail());
                txtProduct.setText(results.get(position).getProduct());
                ratingBar.setRating(results.get(position).getRating());
            }
        });
        DisplayAll();

    }

    public void DisplayAll() {
        results = db.getAllResults();
        ArrayofName.clear();
        for (Result rs : results) {
            ArrayofName.add(rs.getId() + ".\t" + rs.getName() + ", " + rs.getProduct() + ", " + rs.getRating());
            // ArrayofName.add(rs.getId() + ".\t" + rs.getName() + ", " + rs.getPhone() + ", " + rs.getEmail() + ", " + rs.getRating());
        }
        dbAdapter.notifyDataSetChanged();
        txtName.setText("");
        txtPhone.setText("");
        txtEmail.setText("");
        txtProduct.setText("");
        ratingBar.setRating(0);

    }

代码(第2页)

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nearable_demo);
        currentNearable = getIntent().getExtras().getParcelable(ListNearablesActivity.EXTRAS_NEARABLE);
        beaconManager = new BeaconManager(this);

        Desc = (TextView) findViewById(R.id.textview1);   //for description
        COO = (TextView) findViewById(R.id.textview2);//for country of origin
        SM = (TextView) findViewById(R.id.textview3); //for shoe model
        Price = (TextView) findViewById(R.id.textview4); //for price
        SA = (TextView) findViewById(R.id.sa);
        // Get reference of SpinnerView from layout/nearable_demo.xml
        spinnerDropDown = (Spinner) findViewById(R.id.spinner1);  //For size available


        displayCurrentNearableInfo();


        String[] size = stickerdb.getSize(currentNearable.identifier);
        ArrayAdapter<String> adapter= new ArrayAdapter<>
                (this,android.R.layout.simple_spinner_item, size);  //for size available
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerDropDown.setAdapter(adapter);


        scount = stickerdb.getStickerCount(currentNearable.identifier);



btnRating=(Button)findViewById(R.id.rd);
        btnRating.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent pageforRatingBar = new Intent(getApplicationContext(), RatingBar_main.class);
                startActivity(pageforRatingBar);
            }
        });
}

private void displayCurrentNearableInfo() {
        stickerdb = new Database_sticker(this);
        dbRow = stickerdb.getResult(currentNearable.identifier);


        ImageView image = (ImageView) findViewById(R.id.imageView);
        int id = getResources().getIdentifier(dbRow.getSimage(), "drawable", getPackageName());
        image.setImageResource(id);

        dbRow.getId();
        dbRow.getIdentifier();
        dbRow.getScount();

        String desc = dbRow.getDesc().toString();
        dbRow.getSa().toString();
        String coo = dbRow.getCoo().toString();
        String sm = dbRow.getSm().toString();
        String price = dbRow.getPrice().toString();

        //Set the text to the TextView
        Desc.setText(desc);
        COO.setText(coo);
        SM.setText(sm);
        Price.setText("$" + price);
    }

1 个答案:

答案 0 :(得分:1)

你可以。

在您当前的活动中将数据传递给第二个活动,如下所示。

Intent intent = new Intent(CurrentActivity.this,NextActivity.class);
intent.putExtra("key1",value1);
intent.putExtra("key2",value2);
intent.putExtra("key3",value3);
startActivity(intent);

您可以在第二项活动中获取该数据,如下所示。

String str1 = getIntent().getExtras().getString("key1");
String str2 = getIntent().getExtras().getString("key2");
String str3 = getIntent().getExtras().getString("key3");

您还可以传递不同的数据类型(int,float,double,char, all arrays, Bundle, Parceable etc...)