Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将单个文本视图拆分为不同的行_Java_Android - Fatal编程技术网

Java 将单个文本视图拆分为不同的行

Java 将单个文本视图拆分为不同的行,java,android,Java,Android,我需要获得从NFC阅读器传输到我手机的信息,以便在每条线路中安排,例如事件ID、事件名称、日期时间、地点 当我用android应用程序将手机点击到阅读器上时,我得到的只是一串文本。我想将文本打断,以便能够识别事件Id、事件名称、日期时间、地点,以便能够分别获取文本,并将每个文本提交到数据库 这是我的密码 package com.techblogon.loginexample; import java.nio.charset.Charset; import java.util.Arrays;

我需要获得从NFC阅读器传输到我手机的信息,以便在每条线路中安排,例如事件ID、事件名称、日期时间、地点

当我用android应用程序将手机点击到阅读器上时,我得到的只是一串文本。我想将文本打断,以便能够识别事件Id、事件名称、日期时间、地点,以便能够分别获取文本,并将每个文本提交到数据库

这是我的密码

package com.techblogon.loginexample;



import java.nio.charset.Charset;
import java.util.Arrays;

import com.techblogon.loginexample.R;

import android.app.Activity;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcAdapter.OnNdefPushCompleteCallback;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.provider.Settings;
import android.text.format.Time;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

public class UserScreen extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback{

    private static final int MESSAGE_SENT = 1;
    NfcAdapter mNfcAdapter;
    TextView mInfoText;

    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.userscreen);
        mInfoText = (TextView) findViewById(R.id.textView);
        // Check for available NFC Adapter
        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (mNfcAdapter == null) {
            mInfoText = (TextView) findViewById(R.id.textView);
            mInfoText.setText("NFC is not available on this device.");
        }
        // Register callback to set NDEF message
        mNfcAdapter.setNdefPushMessageCallback(this, this);
        // Register callback to listen for message-sent success
        mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    } @Override
    public NdefMessage createNdefMessage(NfcEvent event) {
        Time time = new Time();
        time.setToNow();
        String text = ("Beam me up!\n\n" +
                "Beam Time: " + time.format("%H:%M:%S"));
        NdefMessage msg = new NdefMessage(
              new NdefRecord[] { createMimeRecord("application/com.example.android.beam", text.getBytes()) });
        return msg;
    }

    @Override
    public void onNdefPushComplete(NfcEvent arg0) {
        // A handler is needed to send messages to the activity when this
        // callback occurs, because it happens from a binder thread
        mHandler.obtainMessage(MESSAGE_SENT).sendToTarget();        
        Log.w ("Sent",mHandler.obtainMessage(MESSAGE_SENT).toString());
    }
    /** This handler receives a message from onNdefPushComplete */
    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
            case MESSAGE_SENT:
                Toast.makeText(getApplicationContext(), "Message sent!", Toast.LENGTH_LONG).show();
                break;
            }
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        // Check to see that the Activity started due to an Android Beam
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            processIntent(getIntent());
        }
    }

    @Override
    public void onNewIntent(Intent intent) {
        // onResume gets called after this to handle the intent
        setIntent(intent);
    }

    // Parses the NDEF Message from the intent and prints to the TextView

   void processIntent(Intent intent) {      
       Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
               NfcAdapter.EXTRA_NDEF_MESSAGES);
       // only one message sent during the beam 
       NdefMessage msg = (NdefMessage) rawMsgs[0];
       // record 0 contains the MIME type, record 1 is the AAR, if present
       mInfoText.setText(new String(msg.getRecords()[0].getPayload())); 


   }


   public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
       byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
       NdefRecord mimeRecord = new NdefRecord(
               NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
       return mimeRecord;
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       // If NFC is not available, we won't be needing this menu
       if (mNfcAdapter == null) {
           return super.onCreateOptionsMenu(menu);
       }
       MenuInflater inflater = getMenuInflater();
       inflater.inflate(R.menu.main, menu);
       return true;
   }

   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
           case R.id.menu_settings:
               Intent intent = new Intent(Settings.ACTION_NFCSHARING_SETTINGS);
               startActivity(intent);
               return true;
           default:
               return super.onOptionsItemSelected(item);
       }
   }
    }
试试这个

textView.setText(string1+System.getProperty(“line.separator”)+string2)

编辑:取两个字符串变量,如

String string1 = "Hello";
String string2 = "Android";
然后


字符串1和字符串2来自哪个变量?字符串中包含什么?似乎您正在获取附加值,并且希望分别提取每个附加值。请解释。我获取的字符串是来自NFC阅读器的NDEF消息,该阅读器正在以P2P模式与我的Android应用程序通信。通过public void onNewINtent方法,我获取Ndef消息并将其转换为字符串,以在文本视图上显示为一条直线。我想拆分,以便能够识别拆分的字符串,例如(1个CCN日12.30pm Mensa)到(1个字符串[1]CCN日字符串[2]12.30pm字符串[3]Mensa字符串[4]),不包括括号。Abel将每一行标识为字符串,以便能够通过Web服务将其发送到每一列的数据库。
your_textView.setText(string1 + System.getProperty ("line.separator") + string2);
your_textView.setText("Hello" + System.getProperty ("line.separator") + "Android");