NewMainClass.java
public class NewMainClass extends Activity
{
Button mButton;
ListView mListView;
public static BaseAdapter mAdapter;
public ArrayList<GetProductDetail>temp_GetProductDetails;
GetProductDetail mProductDetail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newmain);
mButton=(Button)findViewById(R.id.btn);
mListView=(ListView)findViewById(R.id.list);
mAdapter=new baseAdapter(NewSecondActivity.mGetProductDetails);
mListView.setAdapter(mAdapter);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent mIntent=new Intent(getApplicationContext(), NewSecondActivity.class);
startActivity(mIntent);
}
});
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Toast.makeText(NewMainClass.this, "You have chosen: " + " " + position, Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onResume() {
super.onResume();
System.out.println("Class Size "+NewSecondActivity.mGetProductDetails.size());
for (int i = 0; i <NewSecondActivity.mGetProductDetails.size(); i++)
{
String s=NewSecondActivity.mGetProductDetails.get(i).getPrice();
System.out.println("Price "+s);
}
}
public class baseAdapter extends BaseAdapter
{
ViewHolder holder ;
public baseAdapter(ArrayList<GetProductDetail> mGetProductDetails)
{
temp_GetProductDetails=mGetProductDetails;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return temp_GetProductDetails.size();
}
@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;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
mProductDetail = temp_GetProductDetails.get(position);
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.newrow, null);
holder.mTextViewAmount=(TextView)convertView.findViewById(R.id.amount);
holder.mTextViewPrice=(TextView)convertView.findViewById(R.id.rate);
holder.mTextViewProduct=(TextView)convertView.findViewById(R.id.productname);
holder.mTextViewQty=(TextView)convertView.findViewById(R.id.qty);
holder.mTextViewAmount.setText(mProductDetail.getAmount());
holder.mTextViewPrice.setText(mProductDetail.getPrice());
holder.mTextViewProduct.setText(mProductDetail.getProduct());
holder.mTextViewQty.setText(mProductDetail.getQty());
return convertView;
}
}
public class ViewHolder
{
TextView mTextViewProduct;
TextView mTextViewPrice;
TextView mTextViewQty;
TextView mTextViewAmount;
}
}
Click below link for download project.
https://sites.google.com/site/nepstareblogspotin/http-nepstare-blogspot-in/DemoArraylist.rar?attredirects=0&d=1
public class NewMainClass extends Activity
{
Button mButton;
ListView mListView;
public static BaseAdapter mAdapter;
public ArrayList<GetProductDetail>temp_GetProductDetails;
GetProductDetail mProductDetail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newmain);
mButton=(Button)findViewById(R.id.btn);
mListView=(ListView)findViewById(R.id.list);
mAdapter=new baseAdapter(NewSecondActivity.mGetProductDetails);
mListView.setAdapter(mAdapter);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent mIntent=new Intent(getApplicationContext(), NewSecondActivity.class);
startActivity(mIntent);
}
});
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Toast.makeText(NewMainClass.this, "You have chosen: " + " " + position, Toast.LENGTH_LONG).show();
}
});
}
@Override
protected void onResume() {
super.onResume();
System.out.println("Class Size "+NewSecondActivity.mGetProductDetails.size());
for (int i = 0; i <NewSecondActivity.mGetProductDetails.size(); i++)
{
String s=NewSecondActivity.mGetProductDetails.get(i).getPrice();
System.out.println("Price "+s);
}
}
public class baseAdapter extends BaseAdapter
{
ViewHolder holder ;
public baseAdapter(ArrayList<GetProductDetail> mGetProductDetails)
{
temp_GetProductDetails=mGetProductDetails;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return temp_GetProductDetails.size();
}
@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;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
mProductDetail = temp_GetProductDetails.get(position);
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.newrow, null);
holder.mTextViewAmount=(TextView)convertView.findViewById(R.id.amount);
holder.mTextViewPrice=(TextView)convertView.findViewById(R.id.rate);
holder.mTextViewProduct=(TextView)convertView.findViewById(R.id.productname);
holder.mTextViewQty=(TextView)convertView.findViewById(R.id.qty);
holder.mTextViewAmount.setText(mProductDetail.getAmount());
holder.mTextViewPrice.setText(mProductDetail.getPrice());
holder.mTextViewProduct.setText(mProductDetail.getProduct());
holder.mTextViewQty.setText(mProductDetail.getQty());
return convertView;
}
}
public class ViewHolder
{
TextView mTextViewProduct;
TextView mTextViewPrice;
TextView mTextViewQty;
TextView mTextViewAmount;
}
}
NewSecondActivity.java
public class NewSecondActivity extends Activity{
EditText mEditTextProductName;
EditText mEditTextQty;
EditText mEditTextPrice;
EditText mEditTextAmount;
Button mButtonSend;
public static ArrayList<GetProductDetail>mGetProductDetails=new ArrayList<GetProductDetail>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondactivity);
mEditTextProductName=(EditText)findViewById(R.id.editText1);
mEditTextQty=(EditText)findViewById(R.id.editText2);
mEditTextPrice=(EditText)findViewById(R.id.editText3);
mEditTextAmount=(EditText)findViewById(R.id.editText4);
mButtonSend=(Button)findViewById(R.id.button1);
mButtonSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GetProductDetail mProductDetail=new GetProductDetail();
mProductDetail.product=mEditTextProductName.getText().toString();
mProductDetail.qty=mEditTextQty.getText().toString();
mProductDetail.price=mEditTextPrice.getText().toString();
mProductDetail.amount=mEditTextAmount.getText().toString();
mGetProductDetails.add(mProductDetail);
NewMainClass.mAdapter.notifyDataSetChanged();
finish();
}
});
}
}
GetProductDetail.java
public class GetProductDetail {
String product="";
String qty="";
String price="";
String amount="";
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public String getQty() {
return qty;
}
public void setQty(String qty) {
this.qty = qty;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
}
Click below link for download project.
https://sites.google.com/site/nepstareblogspotin/http-nepstare-blogspot-in/DemoArraylist.rar?attredirects=0&d=1