2017-08-03 1 views
0

müssen die Daten aus Listenansicht-Adapter zu String-Variable in Android Studio extrahieren.extrahieren Daten von ListView zu Variable in Android-Projekt (Adapter zu Variable)

im Moment sendet es alles zu Tabellenansicht Spalten ich brauche es an Android Studio Logcat senden oder sie in Variable platzieren, damit ich es sonst wo in App verwenden kann.

lvMsg = (ListView) findViewById(R.id.lvMsg); 

    // Create Inbox box URI 
    Uri inboxURI = Uri.parse("content://sms/inbox"); 

    // List required columns 
    String[] reqCols = new String[]{"_id", "address", "body"}; 

    // Get Content Resolver object, which will deal with Content 
    // Provider 
    ContentResolver cr = getContentResolver(); 

    // Fetch Inbox SMS Message from Built-in Content Provider 
    Cursor c = cr.query(inboxURI, reqCols, null, null, null); 

    System.out.println(c); 

    // Attached Cursor with adapter and display in listview 
    adapter = new SimpleCursorAdapter(this, R.layout.row, c, new String[]{"body", "address"}, new int[]{ 
      R.id.lblMsg, R.id.lblNumber 
    }); 

    lvMsg.setAdapter(adapter); 

Antwort

0

Sie benötigen einen Cursor instanziiert und das Element von Ihnen SimpleCursorAdapter mit der Methode getItem (int position) auf SimpleCursorAdapter erhalten.

Cursor Cursor = (Cursor) adapter.getItem (Position)

Sobald Sie den Cursor etwas tun, wie folgt haben.

boolean cursorMove = cursor.moveToFirst(); 
if (cursorMove) 
{ 
    while(cursorMove) 
    { 
    String data = cursor.getString(cursor.getColumnIndex("data")); 
    // your logic here on data 
    cursorMove = cursor.moveToNext() 
    } 
} 
cursor.close(); 

CursorAdapter

Cursor Docs

Verwandte Themen