2017-08-03 4 views
0

リストビューアダプタからアンドロイドスタジオの文字列変数にデータを抽出する必要があります。リストビューからアンドロイドプロジェクト(変数からアダプタ)の変数にデータを抽出

私はそれがアンドロイドスタジオログキャットに送信するか、変数に配置する必要があるので、私はそれがどこにアプリ内で使用することができますtableviewの列にすべてを送信します。

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); 

答えて

0

カーソルをインスタンス化し、SimpleCursorAdapter上のメソッドのgetItem(int型の位置)を使用してSimpleCursorAdapterあなたからアイテムを取得する必要があります。

カーソルcursor =(カーソル)adapter.getItem(位置)

あなたはカーソルを持っていたら、次のような何かを行います。

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

関連する問題