Help me to retreive data

  • Replies:2
ezekel
  • Forum posts: 8

Apr 5, 2014, 10:39:45 AM via Website

HI, I need you help please I am still learning android,..I want to know how can i retrieve the data from my Mysql database?and display it on my android listview ?...Sorry for this silly question I am still a beginner on this android.I hope someone will help me here..


Thank you in advance.

Reply
Lalit
  • Admin
  • Forum posts: 2,324

Apr 7, 2014, 6:43:52 AM via Website

Well if you want to pull the data from that table and list it in the ListView(MainActivity) of my Android app when it's launched(onCreate).
I'm using a a list of items which is premade by me
items table(in mydb database)
id, name, model, year of manufacture, price

package com.example.myproject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener {

protected String[] items = {"Pen", "Pencil", "Sharpener", "Paper"};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
ListView carsList = (ListView) findViewById(R.id.listitems);
itemsList.setAdapter(adapter);
ListView list = (ListView) findViewById(R.id.listitems);
list.setOnItemClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent intent = new Intent(this, DetailsActivity.class);
startActivity(intent);
}
}

— modified on Apr 7, 2014, 6:50:15 AM

ezekel

Reply
ezekel
  • Forum posts: 8

Jun 15, 2014, 6:00:55 AM via Website

John Farrell

Well if you want to pull the data from that table and list it in the ListView(MainActivity) of my Android app when it's launched(onCreate).
I'm using a a list of items which is premade by me
items table(in mydb database)
id, name, model, year of manufacture, price

package com.example.myproject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener {

protected String[] items =  {&quot;Pen&quot;, &quot;Pencil&quot;, &quot;Sharpener&quot;, &quot;Paper&quot;};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ListAdapter adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, items);
    ListView carsList = (ListView) findViewById(R.id.listitems);
    itemsList.setAdapter(adapter);
    ListView list = (ListView) findViewById(R.id.listitems);
    list.setOnItemClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
    Intent intent = new Intent(this, DetailsActivity.class);
    startActivity(intent);
}

}

Hello John,

Thank you for this,sorry for being late reply i forgot my account...Thank you again. :)

Reply