Last active
November 12, 2016 00:23
-
-
Save tmk815/c7efe6eaf713d0bccce77f8e6ee58163 to your computer and use it in GitHub Desktop.
Custom_ListView_Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
DatabaseOpenHelper helper=new DatabaseOpenHelper(this); | |
SQLiteDatabase db; | |
Cursor cursor=null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
db=helper.getWritableDatabase(); | |
ListView listView1 = (ListView)findViewById(R.id.listView); | |
cursor=db.query("tbname",null, null, null, null, null, null); | |
cursor.moveToFirst(); | |
listView1.setAdapter(new SimpleCursorAdapter(this,R.layout.item,cursor,new String[]{ | |
"_id","name","relation","date","place"},new int[]{R.id.id_item,R.id.name_item,R.id.relation,R.id.date_item,R.id.place_item},0)); | |
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
public void onItemClick(AdapterView<?> parent, View view, int position,long id) { | |
//ここで内容取得 | |
String currentId = cursor.getString(cursor.getColumnIndex("name")); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment