I want to write a ListAdaptor method in another class in java. This is the class that I want to add the ListAdaptor method, but I couldn't find any documentation online on how to do this. Thanks!

0 Gagan Deep Singh · October 15, 2015
package com.example.gagandeep.ramyart;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class Profile extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);


//MAKING OF MENU LIST

String[] foods = {"Bacon", "Ham", "Apple", "Spinich", "Heatball", "Potato", "Burger",
"Icecream", "CHOCOLATE", "KIWI", "Bananas", "Meat", "BBQ", "STEAKS"};

 

//THIS BELOW CODE IS USED FOR MENU LISTING WITHOUT THUMBNAIL PIC
ListAdapter guggusAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foods);
ListView profileListView = (ListView) findViewById(R.id.profileListView);
profileListView.setAdapter{guggusAdapter};    //<----- issue with this line
}

 

public void onclick(View view) {
Intent i = new Intent(this, ramyart.class);
startActivity(i);
}


}

Post a Reply

Replies

Oldest  Newest  Rating
0 Gary Whitney · October 15, 2015
I see {} braces instead of parenthesis ().
profileListView.setAdapter{guggusAdapter}; //<----- issue with this line
0 Don Chocho · October 16, 2015
Your onClick method is not referencing a listAdapter class. If you are trying to develop a way to click on each food item and it opens a new page to view more information about the food u clicked, I think you need to have a custom listview class.

Can you explain what you are trying to achieve in plain englishso people on here can understand better?
0 Dol Lod · October 20, 2015
ListViews are outdated. Use recycler views.
0 Gagan Deep Singh · October 20, 2015
thanks guys for your feedback, appreciate.
0 Gagan Deep Singh · October 20, 2015
Now my amendments are this

package com.example.gagandeep.ramyart;


import android.content.Intent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;


public class Profile extends AppCompatActivity {

ArrayAdapter<String> guggusAdapter;

ListView mprofileListView;




@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);


//MAKING OF MENU LIST

String[] foods = {"Bacon", "Ham", "Apple", "Spinich", "Heatball", "Potato", "Burger",
"Icecream", "CHOCOLATE", "KIWI", "Bananas", "Meat", "BBQ", "STEAKS"};

/*//BELOW CODE IS USED FOR OBTAINING THE CODE FROM CUSTOM ADAPTOR JAVA CODING WITH THUMBNAIL PIC
ListAdapter profileAdaptor = new CustomAdaptor(this, foods);*/

//THIS BELOW CODE IS USED FOR MENU LISTING WITHOUT THUMBNAIL PIC
guggusAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foods);
mprofileListView = (ListView) findViewById(R.id.profileListView);
mprofileListView.setAdapter(guggusAdapter);

// BELOW CODING IS USED FOR ACTIVATE THE TAP/CLICK BUTTON OF LIST
mprofileListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String foods = String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(Profile.this, foods, Toast.LENGTH_LONG).show();
}
}

);
}




public void onclick(View view){
Intent i = new Intent(this, Details.class);
startActivity(i);
}



}
0 Gagan Deep Singh · October 20, 2015
its work now
  • 1

Java / Android Development

107,024 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator