Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Listado de información en ListView en lugar de TextView desde la base de datos - Android

Tengo una actividad en mi aplicación que enumera toda la información de mi base de datos en un TextView, sin embargo, quiero imprimir en un ListView en su lugar. No estoy seguro de cómo hacer esto, así que esto es lo que tengo hasta ahora.

 public class ViewMeeting extends Activity implements OnClickListener { EditText deleteText; Button deleteButton; TextView tv; List<MeetingModel> list = new ArrayList<>(); DatabaseHelper db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_meeting); db = new DatabaseHelper(getApplicationContext()); deleteText = (EditText) findViewById(R.id.editText6); deleteButton = (Button) findViewById(R.id.delete1); tv = (TextView) findViewById(textView6); deleteButton.setOnClickListener(this); list = db.getAllMeetingsList(); print(list); } //prints details from database table into a textview private void print(List<MeetingModel> list) { String value = ""; for(MeetingModel sm : list){ value = value+" ID: "+sm.id +"\n" +" Title: "+sm.title +"\n"+" Date: "+sm.date +"\n" + " Time: "+sm.time +"\n" +" Location: "+sm.location+"\n"+"\n"; } tv.setText(value); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Agregue un ListView al diseño de su actividad. Luego, en su función de impresión, pase su lista de reuniones a un ArrayAdapter, luego configúrelo como su adaptador ListView como se muestra a continuación:

 ArrayAdapter adapter = new ArrayAdapter < String > (this, R.layout.LIST_ID, list); ListView listView = (ListView)findViewById(R.id.LIST_ID); listView.setAdapter(adapter);

ACTUALIZAR Su código se verá así:

 public class ViewMeeting extends Activity implements OnClickListener { EditText deleteText; Button deleteButton; TextView tv; List < MeetingModel > list = new ArrayList < > (); DatabaseHelper db; ArrayList meetings = new ArrayList < String > (); ListView listView; @ Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_meeting); listView = (ListView)findViewById(R.id.LIST_ID); db = new DatabaseHelper(getApplicationContext()); deleteText = (EditText)findViewById(R.id.editText6); deleteButton = (Button)findViewById(R.id.delete1); tv = (TextView)findViewById(textView6); deleteButton.setOnClickListener(this); list = db.getAllMeetingsList(); print(list); } //prints details from database table into a textview private void print(List < MeetingModel > list) { String value = ""; for (MeetingModel sm: list) { value = value + " ID: " + sm.id + "\n" + " Title: " + sm.title + "\n" + " Date: " + sm.date + "\n" + " Time: " + sm.time + "\n" + " Location: " + sm.location + "\n" + "\n"; meetings.add(value); } //tv.setText(value); ArrayAdapter adapter = new ArrayAdapter < String > (this, R.layout.LIST_ID, meetings); listView.setAdapter(adapter); } }
over 4 years ago · Santiago Trujillo Report

0

Busque algunos adaptadores para su ListView como ArrayAdapter

https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!