I am using the following code to to display data in my custom list. but it closes with an exception of unsupported operaton. java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
public class VerifiedProblemsActivity extends Activity {
ArrayList<Problem> problemsList;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("IN VERIFIED ACTIVITY", "ACTIVITY");
setContentView(R.layout.verified_problems);
ListView problemsListView = (ListView) findViewById(R.id.problemsList);
ArrayList<Problem> problemsList = new ArrayList<Problem>();
Problem p1 = new Problem();
p1.problemName = "Problem 1";
p1.problemComments = "Comments 1";
Problem p2 = new Problem();
p2.problemName = "Problem 1";
p2.problemComments = "Comments 1";
problemsList.add(p1);
problemsList.add(p2);
problemsListView.setAdapter(new ProblemAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, problemsList));
}
private class Problem {
public String problemName;
public String problemComments;
public Problem() {
problemName = "";
problemComments = "";
}
}
private class ProblemAdapter extends ArrayAdapter<Problem> {
ArrayList<Problem> problemObjects;
#SuppressWarnings("unchecked")
public ProblemAdapter(Context context, int textViewResourceId,
List objects) {
super(context, textViewResourceId, objects);
problemObjects = new ArrayList<Problem>(objects);
// TODO Auto-generated constructor stub
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item, parent);
try {
TextView title = (TextView) row
.findViewById(R.id.tvProblemTitle);
TextView description = (TextView) row
.findViewById(R.id.tvProblemDecription);
title.setText(problemsList.get(position).problemName);
description
.setText(problemsList.get(position).problemComments);
} catch (Exception e) {
Log.d("VERIFIED PROBLEM ACTIVITY", e.getMessage());
}
return row;
}
}
}
and the following is the list item layout I am using.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/imgProblemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/tvProblemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tvProblemDecription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
java.lang.UnsupportedOperationException: addView(View, LayoutParams)
is not supported in AdapterView
I think problem is this:
View row = inflater.inflate(R.layout.list_item, parent);
AdapterView doesn't allow adding new View so you need to pass null as ViewGroup.
View row = inflater.inflate(R.layout.list_item, null, false);
Now it should works. Let me know.
problem in view.
change these methods
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.list_item, parent);
to like this
View row = convertView
if(row==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.list_item, null);
}
hope this will be helpful to you.
Related
I am using this layout to render a dialog
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
style="ThemeDialog"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<CheckBox
android:id="#+id/AddToDictionary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:checked="false"
android:text="Add" />
<Button
android:id="#+id/declineButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm" />
<Button
android:id="#+id/eraseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Erase" />
</LinearLayout>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/border" />
</LinearLayout>
Here is the code in my method to display list of items in an ordinary activity that works very well, but I try to display the same list in a list added to the dialog and this doesn't work although the debugger shows that the reference dialog_suggestions_list_view isn't null neither the array (my arrayAdapter), I need your help to point out where is the problem here, why setAdapter doesn't work with lists in dialogs?
dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.dialog);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.dialog, null);
dialog_suggestions_list_view=(ListView) view.findViewById(R.id.listView2) ;
if(dialog_suggestions_list_view!=null){
dialog_suggestions_list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
String selectedFromList = (String)(dialog_suggestions_list_view.getItemAtPosition(position));
AppCompatEditText fContent = (AppCompatEditText) findViewById(R.id.et_content);
fContent.append(selectedFromList);
fContent.append(" ");
}
});
}else{
Log.i("test","my list not found");
}
ArrayList<String> array=new ArrayList<String>();
array.add("Tic");
array.add("Tac");
array.add("Toe");
ArrayAdapter < String > arrayAdapter = new ArrayAdapter < String > (this, android.R.layout.simple_list_item_1, array);
//display listView in ordianr activity
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(arrayAdapter);
//display listView in dialog
if(dialog_suggestions_list_view!=null){
dialog_suggestions_list_view.setAdapter(arrayAdapter);
}else{
Log.i("test","my list not found");
}
I'm quite confused with your code because it's missing some parts, but i did this see if helps.
dialog = new Dialog(MainActivity.this);
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog), null);
dialog.setContentView(view);
dialog_suggestions_list_view = (ListView) view.findViewById(R.id.listView2);
dialog_suggestions_list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView < ? > parent, View view, int position, long id) {
try {
String selectedFromList = (String)(dialog_suggestions_list_view.getItemAtPosition(position));
AppCompatEditText fContent = (AppCompatEditText) findViewById(R.id.et_content);
fContent.append(selectedFromList);
fContent.append(" ");
} catch (Exception e) {
Log.i("test","my list not found");
}
}
});
}
public ArrayList<String> getList(){
ArrayList<String> array = new ArrayList<String>();
array.add("Tic");
array.add("Tac");
array.add("Toe");
return array;
}
public void setInitialContentValue(){
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getList());
//display listView in ordianr activity
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(arrayAdapter);
//display listView in dialog
try {
dialog_suggestions_list_view.setAdapter(arrayAdapter);
} catch (Exception e) {
Log.i("test","my list not found");
}
}
Hi I am Trying To calculate number like Calculator. the code is working if I use Activity but doesn't work in Sherlock Fragment. I use android:onClick="". Can someone tell what should I do to implement this code. Thank you.
Code :
public class Calculate extends SherlockFragment {
private int resultspinner, inputnumber, totals;
private Spinner spinner;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View rootView = inflater.inflate(R.layout.activity_summary,
container, false);
setSpinnerContent(rootView);
return rootView;
}
private void setSpinnerContent(View view)
{
spinner = (Spinner) view.findViewById( R.id.spinner );
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity()
.getBaseContext(),
R.array.pangkat_arrays, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter( adapter );
...
}
// showing a toast on selecting an item
//Toast.makeText(parent.getContext(), item, Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void startcalculate(View view) {
EditText ed_resultspinner = (EditText) getView().findViewById(R.id.EditText1);
EditText ed_input = (EditText) getView().findViewById(R.id.EditText2);
EditText ed_total = (EditText) getView().findViewById(R.id.EditText3);
try {
resultspinner = Integer.parseInt(ed_resultspinner.getText().toString());
inputnumber = Integer.parseInt(ed_input.getText().toString());
totals = resultspinner + inputnumber;
ed_total.setText(String.valueOf(totals));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startcalculate"
android:text="Button" />
Error
java.lang.IllegalStateException: Could not find a method startcalculate(View) in the activity class com.user.learing.MainActivity for onClick handler on view class android.widget.Button with id 'button1'
this is happening because your SherlockFragment class not finding reference onClick for some reason, you have to do is delete the onClick from layout and sets the code manually like this
Button button1 = (Button) view.findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// your logic
}
});
I'm having problem with HorizontalScrollView, I've set the child layout (LinearLayout) to 2000dp, but still won't scroll. I set the content programmatically.
This is my Activity Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AktifitasUtama" >
<HorizontalScrollView
android:id="#+id/scroll_album_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:fillViewport="true">
<LinearLayout
android:id="#+id/album_holder"
android:layout_width="2000dp"
android:layout_height="wrap_content"
android:orientation="horizontal"></LinearLayout>
</HorizontalScrollView>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/thumbnail_holder"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="180dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
This is my Adapter Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<ImageView
android:id="#+id/grid_item_image"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:layout_marginRight="160dp" >
</ImageView>
<TextView
android:id="#+id/grid_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:layout_marginTop="5dp"
android:textSize="15sp"
android:layout_below="#id/grid_item_image"
android:layout_centerHorizontal="true">
</TextView>
</RelativeLayout>
This is my Activity class
public class AktifitasUtama extends SherlockActivity {
Session session;
HorizontalScrollView scroll_album_holder;
LinearLayout album_holder;
List<String> album_label = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.aktifitas_utama);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Drawable ab = getResources().getDrawable(R.drawable.header);
getSupportActionBar().setBackgroundDrawable(ab);
}
setSupportProgressBarIndeterminateVisibility(true);
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
session = new Session(getApplicationContext());
scroll_album_holder = (HorizontalScrollView) findViewById(R.id.scroll_album_holder);
album_holder = (LinearLayout) findViewById(R.id.album_holder);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.aktifitas_utama, menu);
return (super.onCreateOptionsMenu(menu));
}
#Override
protected void onResume(){
super.onResume();
scroll_album_holder.setVisibility(View.GONE);
if(session.is_login()){
fill_album();
} else {
startActivity(new Intent(getApplicationContext(), AktifitasMasuk.class));
finish();
}
}
public void fill_album(){
album_label.clear();
int i = 2;
if(i==1){
album_label.add("Photo From Camera");
} else if (i==2){
album_label.add("Photo From Camera");
album_label.add("Album 1");
album_label.add("Album 2");
album_label.add("Album 3");
album_label.add("Album 4");
album_label.add("Album 5");
album_label.add("Album 6");
} else if(i==3) {
album_label.add("Album 1");
album_label.add("Album 2");
album_label.add("Album 3");
album_label.add("Album 4");
album_label.add("Album 5");
album_label.add("Album 6");
}
if(!album_label.isEmpty()){
scroll_album_holder.setVisibility(View.VISIBLE);
for(int j=0;j<album_label.size();j++){
album_holder.addView(set_album(album_label.get(j)));
}
}
}
private View set_album(String label){
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View album = inflater.inflate(R.layout.grid, null, false);
ImageView grid_item_image = (ImageView) album.findViewById(R.id.grid_item_image);
TextView grid_item_label = (TextView) album.findViewById(R.id.grid_item_label);
Drawable grid_image = getResources().getDrawable(R.drawable.custom_menu_archive);
grid_item_image.setImageDrawable(grid_image);
grid_item_label.setText(label);
return album;
}
}
So, what do you think? any advice?
I find this very strange behavior of listview and it acts differently on Android 2.1 and 4.1
Here are the 2 classes I wrote which google advises to use for faster performance of ListView.
How to reproduce: Add an entry, check the first checkbox, then add more entries than one page. The checked box floats through the elements!
Here is a small project I wrote: http://tinyurl.com/strange-listview
Anyone can explain the issue or a workaround?
public class AlarmManagerActivity extends Activity {
private PerformanceArrayAdapter mPerformaceArrayAdapter;
private ListView mListView;
private ArrayList<String> mListItems = new ArrayList<String>();
private int mCounter = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView = (ListView) findViewById(R.id.listViewCondition);
mPerformaceArrayAdapter = new PerformanceArrayAdapter(this, mListItems);
mListView.setAdapter(mPerformaceArrayAdapter);
}
public void onClickAdd(View view){
mListItems.add("" + mCounter++);
mPerformaceArrayAdapter.notifyDataSetChanged();
}
}
And here is the main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="#+id/buttonAdd" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Add New Alarm"
android:onClick="onClickAdd" />
<ListView android:id="#+id/listViewCondition"
android:layout_height="wrap_content" android:layout_width="match_parent"></ListView>
</LinearLayout>
And the performance adapter class.
public class PerformanceArrayAdapter extends ArrayAdapter<String> {
private final Activity context;
private final ArrayList<String> mListItems;
static class ViewHolder {
public TextView textView1;
public TextView textView2;
public CheckBox checkBox;
}
public PerformanceArrayAdapter(Activity context, ArrayList<String> listItems) {
super(context, R.layout.row_layout, listItems);
this.context = context;
this.mListItems = listItems;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.row_layout, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.textView1 = (TextView) rowView.findViewById(R.id.textView1);
viewHolder.textView2 = (TextView) rowView.findViewById(R.id.textView2);
viewHolder.checkBox = (CheckBox) rowView.findViewById(R.id.checkBox1);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.textView1.setText(mListItems.get(position));
return rowView;
}
}
Here is the row_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:id="#+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:text="TextView1"></TextView>
<TextView android:id="#+id/textView2" android:layout_below="#+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="TextView2"></TextView>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/checkBox1"
android:layout_alignParentRight="true" android:focusable="false"
android:focusableInTouchMode="false"></CheckBox>
</RelativeLayout>
I found the solution, thanks to Vogella :)
I had to use the Domain Model mentioned here to track both the text view and check box.
http://www.vogella.com/articles/AndroidListView/article.html#listadvanced_interactive
I'm trying to implement a ListView with a title. However, with my code below, the following happens :
the title appears over the first list element.
There is a EditText which appears in front of the others on the top.
My android Activity
public class LoanRepaymentActivity extends ListActivity implements View.OnClickListener {
private Location lastKnownLocation;
private ArrayList<CurrentRepaymentInstallment> loansForRepayment;
#Override
public void onCreate(Bundle savedInstanceState){
lastKnownLocation = Utility.getLastKnownLocation(this);
super.onCreate(savedInstanceState);
Intent intent = getIntent();
RepaymentInfo repaymentInfo = (RepaymentInfo)intent.getSerializableExtra(Constants.CURRENT_REPAYMENT_INSTALLMENT);
loansForRepayment = repaymentInfo.getLoansForRepayment();
boolean repaymentsNotPresent = loansForRepayment == null || loansForRepayment.isEmpty();
if(repaymentsNotPresent){
Dialog dialog = Utility.getDialogWithText(LoanRepaymentActivity.this, getText(R.string.noLoansForRepayment).toString());
Utility.getDialogButton(dialog, LoanRepaymentActivity.this, PartnerGroupListActivity.class, intent.getStringExtra(Constants.ACECSS_TOKEN_PARAM));
dialog.show();
}
setContentView(R.layout.loan_repayments);
ArrayAdapter<CurrentRepaymentInstallment> adapter = new LoanRepaymentListAdapter(this, loansForRepayment);
View footer = getLayoutInflater().inflate(R.layout.loan_disbursement_footer, null);
getListView().addFooterView(footer);
setListAdapter(adapter);
if(!repaymentsNotPresent) {
TextView textView = (TextView)findViewById(R.id.screenTitle);
String currentInstallmentLabel = getText(R.string.currentInstallmentLabel).toString() + repaymentInfo.getCurrentGroupInstallment();
textView.setText(currentInstallmentLabel);
}
Button button = (Button)findViewById(R.id.disburse);
button.setOnClickListener(this);
}
The XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView android:id="#+id/screenTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+layout/loan_disbursement_footer"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/borrowerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="14sp"
>
</TextView>
<TextView
android:id="#+id/loanAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="14sp"
>
</TextView>
<TextView
android:id="#+id/installmentNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="12sp"
>
</TextView>
<TextView
android:id="#+id/estimatedTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="12sp"
>
</TextView>
</LinearLayout>
<EditText
android:id="#+id/repaymentAmount"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:inputType="numberDecimal"
android:textSize="12sp"
>
</EditText>
Custom Array Adapter
public class LoanRepaymentListAdapter extends ArrayAdapter<CurrentRepaymentInstallment> {
private final List<CurrentRepaymentInstallment> loansForRepayment;
private final Activity context;
public LoanRepaymentListAdapter(Activity context, List<CurrentRepaymentInstallment> loansForRepayment) {
super(context, R.layout.loan_repayments, loansForRepayment);
this.context = context;
this.loansForRepayment = loansForRepayment;
}
static class ViewHolder {
protected TextView borrowerName;
protected TextView loanAmount;
protected TextView installmentNumber;
protected TextView estimatedTotal;
protected EditText repaymentAmount;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.loan_repayments, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.borrowerName = (TextView) view.findViewById(R.id.borrowerName);
viewHolder.loanAmount = (TextView) view.findViewById(R.id.loanAmount);
viewHolder.installmentNumber = (TextView) view.findViewById(R.id.installmentNumber);
viewHolder.estimatedTotal = (TextView) view.findViewById(R.id.estimatedTotal);
viewHolder.repaymentAmount = (EditText) view.findViewById(R.id.repaymentAmount);
// viewHolder.repaymentAmount.setEditableFactory(Editable.Factory.getInstance());
viewHolder.repaymentAmount.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable arg0) {
}
#Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String repaymentAmount = s.toString();
try {
loansForRepayment.get(position).setRepaymentAmount(Float.parseFloat(repaymentAmount));
} catch (Exception ex){
loansForRepayment.get(position).setRepaymentAmount(0.0F);
}
}
});
view.setTag(viewHolder);
viewHolder.repaymentAmount.setTag(loansForRepayment.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).repaymentAmount.setTag(loansForRepayment.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.borrowerName.setText(loansForRepayment.get(position).getLoanProfileBasicInfo().getBorrowerBasicInfo().getFirstName());
holder.loanAmount.setText("Rs. " + Float.toString(loansForRepayment.get(position).getLoanProfileBasicInfo().getLoanAmountInPaisa()/100));
holder.estimatedTotal.setText("Rs. " + Float.toString(loansForRepayment.get(position).getEstimatedTotalAmount()/100));
holder.installmentNumber.setText("Inst no : " + Integer.toString(loansForRepayment.get(position).getInstallmentNumber()));
float repaymentAmt = loansForRepayment.get(position).getRepaymentAmount();
if(repaymentAmt != 0.0) holder.repaymentAmount.setText(Float.toString(repaymentAmt));
return view;
}
}
Would be great if someone could tell me how to do this.
Set a new layout for the title and add it to the ListView as a header.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
>
<TextView android:id="#+id/repaymentScreenTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/repaymentsTitle" >
</TextView>
</LinearLayout>
Replace this block with the one below it in your Activity
if(!repaymentsNotPresent) {
TextView textView = (TextView)findViewById(R.id.screenTitle);
String currentInstallmentLabel = getText(R.string.currentInstallmentLabel).toString() + repaymentInfo.getCurrentGroupInstallment();
textView.setText(currentInstallmentLabel);
}
View headerView = getLayoutInflater().inflate(R.layout.loan_repayment_title, null);
TextView titleView = (TextView) headerView.findViewById(R.id.repaymentScreenTitle);
String titlePrefix = (String) getText(R.string.groupInstallmentLabel);
titleView.setText(titlePrefix + " " + repaymentInfo.getCurrentGroupInstallment());
getListView().addHeaderView(headerView);