English 中文(简体)
EditText 方框内容在点击Button后列入关于安乐文的文View。
原标题:EditText box contents into ListView on Android after clicking Button

想看到有人能帮助我如何把埃迪特Text箱的内容列入安康岛名单。 我有一个项目Im在这项工作中工作,利用Barcode Scanner扫描条码,并将结果退回EditText箱。

I m now attempting to code the contents of the EditText box with the use of a button to add the contents in the list either within that activity or on another one. I ve looked at the simple note list example and a couple of other examples, however, when I try and implement some of the same concepts, I get no where or I think I get somewhere, but the code does nothing. I m sorry it s late.. been up all night trying to figure this out... Any help, advice, is greatly and always appreciated...

package com.terrellmcqueen.databaseproject474;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class Main extends Activity implements OnClickListener {
    private static final int REQUEST_BARCODE = 0;
    private TextView mBarcodeEdit;
    private TextView mScanButton;

    // private fields omitted

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mBarcodeEdit = (EditText) findViewById(R.id.myEditText);
        mScanButton = (Button) findViewById(R.id.scanButton);
        mScanButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.scanButton:
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "SCAN_MODE");
                startActivityForResult(intent, REQUEST_BARCODE);
                break;
        }
     }

     public void onClick1(View v) {
         switch (v.getId()) {
             case R.id.btnSimple:    
                 ListView myListView = (ListView) findViewById(R.id.myListView);
                 final EditText myEditText = (EditText) findViewById(R.id.myEditText);        
                 final ArrayList<String> noteList = new ArrayList<String>();
                 final ArrayAdapter<String> aa;

                 // binding an array of Strings 
                 aa = new ArrayAdapter<String>(this, 
                         android.R.layout.simple_list_item_1,noteList);

                 // here we set the adapter, this turns it on
                 myListView.setAdapter(aa);

                 // here is the button
                 // Button btnSimple = (Button) findViewById(R.id.btnSimple);

                 //  String barcode = mBarcodeEdit.getText().toString();

                 //  String title = mTitleEdit.getText().toString();
                 //  String price = mPriceEdit.getText().toString();
            }
      }

    public void onActivityResult(int requestCode,int resultCode, Intent intent) {
        if (requestCode == REQUEST_BARCODE) {
            if (resultCode == RESULT_OK) {
                String barcode = intent.getStringExtra("SCAN_RESULT");
                mBarcodeEdit.setText(barcode);
            } else if (resultCode == RESULT_CANCELED) {
                finish();
            }
        }
    }
}
最佳回答

我对法典做了微小改动,并根据你的要求开展工作,请看一下。

package com.barcode;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class BarcodeActivity extends Activity implements OnClickListener {
    private static final int REQUEST_BARCODE = 0;
    private TextView mBarcodeEdit;
    private Button mScanButton;
    private Button mAddButton;

    // private fields omitted

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mBarcodeEdit = (EditText) findViewById(R.id.editText1);
        mScanButton = (Button) findViewById(R.id.button1);
        mAddButton = (Button) findViewById(R.id.add);
        mScanButton.setOnClickListener(this);
        mAddButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "SCAN_MODE");
            startActivityForResult(intent, REQUEST_BARCODE);
            break;
        case R.id.add:
            ListView myListView = (ListView) findViewById(R.id.listView1);
            final EditText myEditText = (EditText) findViewById(R.id.editText1);
            final ArrayList<String> noteList = new ArrayList<String>();
            noteList.add(myEditText.getText().toString());
            final ArrayAdapter<String> aa;

            // binding an array of Strings
            aa = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, noteList);

            // here we set the adapter, this turns it on
            myListView.setAdapter(aa);
            break;
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == REQUEST_BARCODE) {
            if (resultCode == RESULT_OK) {
                String barcode = intent.getStringExtra("SCAN_RESULT");
                mBarcodeEdit.setText(barcode);
            } else if (resultCode == RESULT_CANCELED) {
                finish();
            }
        }
    }
}
问题回答

在纽芬兰的点击活动中,在用于填满清单的名单上添加ed粒,并打电话给你ArrayAdapter的通知DataSetChanged()。 希望会奏效。

noteList.add(mBarcodeEdit.getText());
aa.notifyDataSetChanged();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签