main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/MyList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="afterDescendants"
android:cacheColorHint="@android:color/transparent"
android:fadingEdge="none" >
</ListView>
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dfd" />
<EditText
android:id="@+id/ItemCaption"
android:editable="true"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
>
</EditText>
</LinearLayout>
NewMain.Java
package com.example.editwithlist;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class NewMain extends Activity {
ListView mListView;
int qty=1;
DatabaseConnectionAPI mDatabaseConnectionAPI;
ArrayList<ParserCategory> mArrayList;
InteractiveListViewAdapter mInteractiveListViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabaseConnectionAPI = new DatabaseConnectionAPI(
getApplicationContext());
try {
mDatabaseConnectionAPI.createDataBase();
mDatabaseConnectionAPI.openDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mArrayList = new ArrayList<ParserCategory>();
mArrayList = mDatabaseConnectionAPI.getCategoryData();
mListView = (ListView) findViewById(R.id.MyList);
mInteractiveListViewAdapter=new InteractiveListViewAdapter(NewMain.this,R.layout.item,mArrayList);
mListView.setAdapter(mInteractiveListViewAdapter);
}
public class ViewHolder {
TextView text;
EditText scores;
}
public class InteractiveListViewAdapter extends ArrayAdapter<ParserCategory>
{
ArrayList<ParserCategory>mList;
Activity context;
ViewHolder viewHolder;
public InteractiveListViewAdapter(Context context, int resource,ArrayList<ParserCategory> mArrayList) {
super(context, R.layout.item,mArrayList);
this.context=(Activity) context;
mList=mArrayList;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View view = null;
if (convertView == null)
{
LayoutInflater inflator = getLayoutInflater();
view = inflator.inflate(R.layout.item, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.txt);
viewHolder.scores=(EditText) view.findViewById(R.id.ItemCaption);
viewHolder.scores.setText(mArrayList.get(position).getQty());
viewHolder.scores.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count) {
ParserCategory element=(ParserCategory)viewHolder.scores.getTag();
element.setQty(s.toString());
}
public void beforeTextChanged(CharSequence s, int start, int count,int after)
{
}
public void afterTextChanged(Editable s)
{
}
});
viewHolder.scores.setTag(mList.get(position));
viewHolder.scores.setId(position);
view.setTag(viewHolder);
}
else
{
view = convertView;
((ViewHolder) view.getTag()).scores.setTag(mList.get(position));
}
viewHolder = (ViewHolder) view.getTag();
viewHolder.text.setText(mList.get(position).getCname());
viewHolder.scores.setText(mList.get(position).getQty());
return view;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/MyList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="afterDescendants"
android:cacheColorHint="@android:color/transparent"
android:fadingEdge="none" >
</ListView>
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dfd" />
<EditText
android:id="@+id/ItemCaption"
android:editable="true"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
>
</EditText>
</LinearLayout>
NewMain.Java
package com.example.editwithlist;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class NewMain extends Activity {
ListView mListView;
int qty=1;
DatabaseConnectionAPI mDatabaseConnectionAPI;
ArrayList<ParserCategory> mArrayList;
InteractiveListViewAdapter mInteractiveListViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabaseConnectionAPI = new DatabaseConnectionAPI(
getApplicationContext());
try {
mDatabaseConnectionAPI.createDataBase();
mDatabaseConnectionAPI.openDataBase();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mArrayList = new ArrayList<ParserCategory>();
mArrayList = mDatabaseConnectionAPI.getCategoryData();
mListView = (ListView) findViewById(R.id.MyList);
mInteractiveListViewAdapter=new InteractiveListViewAdapter(NewMain.this,R.layout.item,mArrayList);
mListView.setAdapter(mInteractiveListViewAdapter);
}
public class ViewHolder {
TextView text;
EditText scores;
}
public class InteractiveListViewAdapter extends ArrayAdapter<ParserCategory>
{
ArrayList<ParserCategory>mList;
Activity context;
ViewHolder viewHolder;
public InteractiveListViewAdapter(Context context, int resource,ArrayList<ParserCategory> mArrayList) {
super(context, R.layout.item,mArrayList);
this.context=(Activity) context;
mList=mArrayList;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View view = null;
if (convertView == null)
{
LayoutInflater inflator = getLayoutInflater();
view = inflator.inflate(R.layout.item, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.txt);
viewHolder.scores=(EditText) view.findViewById(R.id.ItemCaption);
viewHolder.scores.setText(mArrayList.get(position).getQty());
viewHolder.scores.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count) {
ParserCategory element=(ParserCategory)viewHolder.scores.getTag();
element.setQty(s.toString());
}
public void beforeTextChanged(CharSequence s, int start, int count,int after)
{
}
public void afterTextChanged(Editable s)
{
}
});
viewHolder.scores.setTag(mList.get(position));
viewHolder.scores.setId(position);
view.setTag(viewHolder);
}
else
{
view = convertView;
((ViewHolder) view.getTag()).scores.setTag(mList.get(position));
}
viewHolder = (ViewHolder) view.getTag();
viewHolder.text.setText(mList.get(position).getCname());
viewHolder.scores.setText(mList.get(position).getQty());
return view;
}
}
}
No comments:
Post a Comment