I got the problem when I tried to add switch case in custom page adapter. I can toast if one item of gridview is clicked. But when I tried to add new activity with onClick, app is crashed. I want to show new activity if gridview item is clicked. I've searched and studied regarding this problem, but I can't find solution.I think my problem is related to switch case. I am learning android. Please help me.
CustomAdapter.java
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class CustomAdapter extends BaseAdapter{
String [] result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity, String[] osNameList, int[] osImages) {
// TODO Auto-generated constructor stub
result=osNameList;
context=mainActivity;
imageId=osImages;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return result.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView os_text;
ImageView os_img;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.sample_gridlayout, null);
holder.os_text =(TextView) rowView.findViewById(R.id.os_texts);
holder.os_img =(ImageView) rowView.findViewById(R.id.os_images);
holder.os_text.setText(result[position]);
holder.os_img.setImageResource(imageId[position]);
rowView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
switch(position){
case 0:
Intent a = new Intent(v.getContext(), FirstActivity.class);
v.getContext().startActivity(a);
break;
case 1:
Intent b = new Intent(v.getContext(), DefaultActivity.class);
v.getContext().startActivity(b);
break;
}
} });
return rowView;
}
}
MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
public class MainActivity extends Activity {
GridView gridview;
public static String[] osNameList = {
"Android",
"iOS",
"Linux",
};
public static int[] osImages = {
R.drawable.alpha,
R.drawable.beta,
R.drawable.cupcake,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview = (GridView) findViewById(R.id.customgrid);
gridview.setAdapter(new CustomAdapter(this, osNameList, osImages));
}
}
This is not the way to set OnItemClick Listener. If you want to set click on whole item you should use OnItemClickListener. Remove the OnClickListener from getView() and use OnItemClickListener as follows.
GridView gridview = (GridView) findViewById(R.id.customgrid);
gridview.setAdapter(new CustomAdapter(this, osNameList, osImages));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position){
case 0:
Intent a = new Intent(v.getContext(), FirstActivity.class);
startActivity(a);
break;
case 1:
Intent b = new Intent(v.getContext(), DefaultActivity.class);
startActivity(b);
break;
default:
break;
}
} });
NOTE:- There is no need of switch inside OnClickListener which is inside getView() because its only going to call for one position at a time.
Related
I have a small app that uses a ListView, each item having a play button, an open/close button, and an ImageView whose visibilty is set to View.GONE. When I press the open/close button, it should set the ImageView in that one list item to View.VISIBLE, change the open/close button, and close any other list items that are displaying the ImageView as VISIBLE and change their open/close button to reflect closed. This is my onClick in my custom ArrayAdapter.
boolean open = false;
imgOpen_Close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!open){
openClose.setImageResource(R.drawable.open_arrow);
mainImage.setVisibility(View.VISIBLE);
open = true;
}else{
openClose.setImageResource(R.drawable.close_arrow);
mainImage.setVisibility(View.VISIBLE);
open = false;
}
});
How do I access a View in one list item from another list item?
Entire Custom ArrayAdapter.
package net.androidbootcamp.mypersonalplaylist;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyListAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] songs;
private final Integer[] imgID;
MediaPlayer mpKickStart, mpGirlsGirls, mpHomeSweetHome;
public MyListAdapter(Activity context, String[] songs, Integer[] imgID){
super(context, R.layout.list_view_custom, songs);
this.context=context;
this.songs=songs;
this.imgID=imgID;
}
public View getView(final int position, View view, ViewGroup parent){
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_view_custom, null, true);
TextView txtSongName = rowView.findViewById(R.id.txtSongName);
final ImageView imgCoverArt = rowView.findViewById(R.id.imgCoverArt);
final ImageView imgPlayButton = rowView.findViewById(R.id.imgPlayButton);
final ImageView imgOpen_Close = rowView.findViewById(R.id.imgOpen_Close);
txtSongName.setText(songs[position]);
imgCoverArt.setImageResource(imgID[position]);
mpKickStart = new MediaPlayer();
mpKickStart = MediaPlayer.create(context, R.raw.kickstartmyheart);
mpGirlsGirls = new MediaPlayer();
mpGirlsGirls = MediaPlayer.create(context, R.raw.girlsgirlsgirls);
mpHomeSweetHome = new MediaPlayer();
mpHomeSweetHome = MediaPlayer.create(context, R.raw.homesweethome);
imgPlayButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (position){
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
}
});
imgOpen_Close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("POSITION", "Position Clicked: " + position);
}
});
return rowView;
}
}
MainActivity
package net.androidbootcamp.mypersonalplaylist;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
ListView list;
String[] songs = {"Name 1", "Name 2", "Name 3"};
Integer[] imgID = {R.drawable.kickstart_my_heart, R.drawable.girls_girls_girls, R.drawable.home_sweet_home};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyListAdapter adapter = new MyListAdapter(this, songs, imgID);
list = findViewById(R.id.listView);
list.setAdapter(adapter);
}
}
My App works perfectly at loading all the events and activities. However, when I try to load an Activity containing RecyclerView to show some stored strings. It crashes and finish.
I don´t know if the syntax is wrong or maybe the logic of the code itself.
I am calling the activity from a listener
Object parceable to the new activity:
final public FrasesProvisional frases = new FrasesProvisional();
Method starting the activity:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.config:
lanzarConfiguracion(null);
break;
case R.id.about:
lanzarAbout(null);
break;
case R.id.mismotivaciones:
abrirMotivaciones(null);
break;
}
return true;
}
private void abrirMotivaciones(View view) {
Intent i = new Intent(this, MotivacionesUser.class);
startActivity(i);
}
Activity content:
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
/**
* Created by Pablo on 14/01/2017.
*/
public class MotivacionesUser extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutMmanager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.motivacionesrecycler);
FrasesProvisional frases = getIntent().getParcelableExtra("frases");
mRecyclerView = (RecyclerView) findViewById(R.id.motivaciones_recycler);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
//Init LayoutManager
mLayoutMmanager = new LinearLayoutManager(this); //Podemos elegir entre LinearM, GridM o ScrappableM en relación al estilo que queramos
mRecyclerView.setLayoutManager(mLayoutMmanager); //Set the Layout to the RrecyclerView
mAdapter = new RecyclerAdaptador(frases.getArrayList()); //Especificamos el adaptador a usar y lo agenciamos al Recycler
mRecyclerView.setAdapter(mAdapter);
}
}
RecyclerView code:
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Pablo on 14/01/2017.
*/
public class RecyclerAdaptador extends RecyclerView.Adapter < RecyclerAdaptador.ViewHolder > {
private ArrayList < String > frases;
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView mTextView;
public ViewHolder(View v) {
super(v); //Inicializa el textview
mTextView = (TextView) v.findViewById(R.id.text_recycler);
}
}
public RecyclerAdaptador(ArrayList < String > frases) {
this.frases = frases;
}
#Override
public RecyclerAdaptador.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//Create a new view
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.frase_recycler, parent, false);
ViewHolder vh = new ViewHolder(view);
return vh;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
//Get element of the data set at the position x and replace the content of the rextView with it
holder.mTextView.setText(frases.get(position));
}
#Override
public int getItemCount() {
return frases.size();
}
}
Thanks in advance!
Looking at your code, you create the activity through the following snippet:
Intent i = new Intent(this, MotivacionesUser.class);
startActivity(i);
However in the activity you try to read out extra data in FrasesProvisional frases = getIntent().getParcelableExtra("frases");.
Since you never attached that data to the intent that would return null.
You then use it without checking if it was null at new RecyclerAdaptador(frases.getArrayList());, causing a NullPointerException and crashing your class.
Add a class variable
Context context;
public RecyclerAdaptador(Context context,ArrayList<String> frases) {
this.context=context
this.frases = frases;
}
from activity
mAdapter = new RecyclerAdaptador(this,frases.getArrayList());
I've created a new activity with swipe views, and added some code.
I have now two swipeable pages, but with the same content, how can i change the content of the second swipe page.
Do I have to create a new activity or just to redirect it to another xml?
import java.util.Locale;
import android.graphics.Bitmap;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
public class ListItemClicked extends ActionBarActivity {
static Bundle extras;
SectionsPagerAdapter mSectionsPagerAdapter;
static ImageLoader imageLoader;
static DisplayImageOptions options;
ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_item_clicked);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
extras = getIntent().getExtras();
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
//Setup the ImageLoader, we'll use this to display our images
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
//Setup options for ImageLoader so it will handle caching for us.
options = new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.build();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return PlaceholderFragment.newInstance(position + 1);
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section4).toUpperCase(l);
case 1:
return getString(R.string.title_section5).toUpperCase(l);
}
return null;
}
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_list_item_clicked, container, false);
TextView pDate = (TextView) rootView.findViewById(R.id.textView);
pDate.setText( extras.getString("pdate") );
TextView ptitle = (TextView) rootView.findViewById(R.id.section_label);
ptitle.setText(extras.getString("pname"));
TextView pnText = (TextView) rootView.findViewById(R.id.textView2);
pnText.setText( extras.getString("pText"));
//Setup a listener we can use to swtich from the loading indicator to the Image once it's ready
ImageLoadingListener listener = new ImageLoadingListener(){
#Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
// i/ndicator.setVisibility(View.INVISIBLE);
// iconImg.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub
}
};
//Load the image and use our options so caching is handled.
final ImageView iconImg = (ImageView) rootView.findViewById(R.id.imageView);
imageLoader.displayImage( extras.getString("pImage"), iconImg, options, listener);
return rootView;
}
}
}
thanks!
based on the page number you get from Placeholder Fragment you can set the new content
on your PlaceholderFragment class you can get current page position passed from newInstance method.after that, you can change your fragment content according page section number
There are many ways to do this. You don't have to create another Activity.
Below is a simple way, it rewrites your PlaceholderFragment and make it return different view in different position on onCreateView.
public static class PlaceholderFragment extends Fragment {
private int position;
public static PlaceholderFragment newInstance(int sectionNumber) {
return new PlaceholderFragment(sectionNumber);
}
public PlaceholderFragment(int sectionNumber) {
this.position = sectionNumber;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView;
switch(position){
case 1:
rootView = inflater.inflate(..);
//init view widget.
break;
case 2:
rootView = inflater.inflate(..);
//init view widget.
break;
}
return rootView;
}
}
Edited code after following this link ...Set wallpaper from ViewPager .I developed simple viewpager app along with the background music. However, I want to modify my app so that image chosen by user will give them option to set as wallpaper....I don't want to implement any buttons in my app. User should be able to just touch the image , which will give them option to set as wallpaper...
I am getting error at this code curruntPosition=arg0;. It says "Current position cannot be resolve to a variable". I don't know what it mean ...
Following are my codes...
Mainactivity.java
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
public class MainActivity extends Activity {
MediaPlayer oursong;
ViewPager viewPager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
oursong = MediaPlayer.create(MainActivity.this, R.raw.a);
oursong.start ();
viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
//Here you can set the wallpaper
curruntPosition=arg0;
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
}
private ShareActionProvider mShareActionProvider;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate menu resource file.
getMenuInflater().inflate(R.menu.activity_main, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
// Return true to display menu
return true;
}
// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
#Override
protected void onPause(){
super.onPause();
oursong.release();
oursong = null;
}
}
imageadapter.java
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class ImageAdapter extends PagerAdapter {
Context context;
private int[] GalImages = new int[] {
R.drawable.one,
R.drawable.two,
R.drawable.three
};
ImageAdapter(Context context){
this.context=context;
}
#Override
public int getCount() {
return GalImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_small);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
I just start with programming, so please give some explanations, or it will be great if you provide some codes .
First add this Permission to the Manifest
<uses-permission android:name="android.permission.SET_WALLPAPER">
Now for some code.
imageview.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(context);
try {
myWallpaperManager.setResource(GalImages[position]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Explantion : This will set that the Image will be clickable , when the image is clicked it will set the phone Wallpaper with the selected drawable.
getApplicationContext()
is the Context from the Activity.
This changes will take place inside the Adapter.
Activity
add this variable
int currentPosition;
I am trying to populate an arraylist with three variable. After that the arraylist should display its content in a listview. when i run this class logcat shows an error which is completely unknown to me. Following is the class I am using.
import java.util.ArrayList;
import android.app.Activity;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Secondscreen extends Activity {
String pName ;
int pPrice;
String pDisc;
int total;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondscreen);
ListView lv= (ListView) findViewById(R.id.listView1);
//TextView showCartContent = (TextView) findViewById(R.id.showCart);
final Button thirdBtn = (Button) findViewById(R.id.third);
//final LinearLayout lb = (LinearLayout) findViewById(R.id.secondLinear);
final Controller aController = (Controller) getApplicationContext();
final int cartSize = aController.getCart().getCartSize();
final ArrayList<Listitem> arrayList=new ArrayList<Listitem>();
BaseAdapter adapter= new BaseAdapter(){
#Override
public int getCount() {
// TODO Auto-generated method stub
return arrayList.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrayList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
#Override
public View getView(int position, View view, ViewGroup viewgroup) {
if (view == null) {
view=inflater.inflate(R.layout.pattern, null);
}
TextView tv=(TextView) view.findViewById(R.id.nameview);
TextView tv2=(TextView) view.findViewById(R.id.pdesc);
TextView tv3=(TextView) view.findViewById(R.id.priceView);
tv.setText(pName);
tv2.setText(pPrice);
tv3.setText(pDisc);
return view;
}
};
lv.setAdapter(adapter);
if(cartSize >0)
{
for(int i=0;i<cartSize;i++)
{
pName = aController.getCart().getProducts(i).getProductName();
pPrice = aController.getCart().getProducts(i).getProductPrice();
pDisc = aController.getCart().getProducts(i).getProductDesc();
Listitem item=new Listitem(pName, pPrice,pDisc);
arrayList.add(item);
adapter.notifyDataSetChanged();
}
}
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
Please Help me to solve this.
tv2.setText(pPrice);
pPrice is a int. setText(int) looks for a String id inside the R classes throwing a ResourceNotFoundException if the look-up fails. A quick fix is
tv2.setText(""+pPrice);
This way you are providing a String object to setText
Edit:
Change your getView this way:
#Override
public View getView(int position, View view, ViewGroup viewgroup) {
if (view == null) {
view=inflater.inflate(R.layout.pattern, null);
}
Listitem item = (Listitem)getItem(position)
TextView tv=(TextView) view.findViewById(R.id.nameview);
TextView tv2=(TextView) view.findViewById(R.id.pdesc);
TextView tv3=(TextView) view.findViewById(R.id.priceView);
tv.setText(item. pName);
tv2.setText(""+item.pPrice);
tv3.setText(item.pDisc);
return view;
}
You never get your objects from the ArrayList. Add this code to your getView() method:
ListItem item = arrayList.get(position);
tv.setText(item.pName);
tv2.setText(item.pPrice);
tv3.setText(item.pDisc);