Calculation using Textwatch - java

the question I going to ask, might be kind of complicated.
Pardon me, if I can't explain it clearly.
It's my first time having touch with android coding.
I would like to do a calculation doing android .
It's about Fuel Log.
What I want to do right now is
When I keep in the price(edittext) and pump(edittext),
the output will be shown straight away in the cost(textview), that I've placed.
I would want to do that,
but I don't think I have did the right coding for it.
I've tried out myself,
but I didn't run the application, cause I think that the codes I've done is not fully completed/right.
I would love to hear the advice from you guys.
Could someone please help me out with it?
Thank you,
your help will be much appreciate.
(:
MainActivity.java
public class MainActivity extends Activity {
Button saveButton = null;
EditText dateEdit;
EditText priceEdit;
EditText pumpEdit;
TextView costView;
EditText odometerEdit;
TextView fconView;
public boolean isNumeric(String str)
{
return str.matches("-?\\d+(\\.\\d+)?");
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle bundle = getIntent().getExtras();
float price = Float.parseFloat(bundle.getString("priceEdit"));
float pump = Float.parseFloat(bundle.getString("pumpEdit"));
costView = (TextView)findViewById(R.id.tcost);
dateEdit = (EditText)findViewById(R.id.date);
priceEdit = (EditText)findViewById(R.id.fuelprice);
pumpEdit = (EditText)findViewById(R.id.fuelpump);
TextWatcher mCostChangeWatcher = new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
if(!TextUtils.isEmpty(priceEdit.getText()) && !TextUtils.isEmpty(pumpEdit.getText())){
costView.setText(calculateCost(priceEdit.getText(), pumpEdit.getText()));
}
}
private float calculateCost(float price, float pump) {
final float costCal = (price * pump);
return costCal;
// TODO Auto-generated method stub
}
};
priceEdit.addTextChangedListener(mCostChangeWatcher);
pumpEdit.addTextChangedListener(mCostChangeWatcher);
saveButton = (Button) findViewById(R.id.saveBTN);
saveButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
DBAdapter dbAdaptor = new DBAdapter(getApplicationContext());
try
{
dbAdaptor.open();
String date = dateEdit.getText().toString();
String price = priceEdit.getText().toString();
String pump = pumpEdit.getText().toString();
String cost = Float.toString();
String odometer = odometerEdit.getText().toString();
String fcon = fconView.getText().toString();
dbAdaptor.insertLog(date, price, pump, cost, odometer, fcon);
}
catch(Exception e){
Log.d("Fuel Log", e.getMessage());
}
finally
{
if(dbAdaptor != null)
dbAdaptor.close();
}
}
});
}//oncreate
}//main
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/datetxtview"
android:text="#string/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/date"
android:text=""
android:inputType="date"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/fuelpricetxtview"
android:text="#string/fuelprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/fuelprice"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/fuelpumptxtview"
android:text="#string/fuelpump"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/fuelpump"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/totalcosttxtview"
android:text="#string/totalcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="#+id/tcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/odometertxtview"
android:text="#string/odometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:id="#+id/odometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/fctxtview"
android:text="#string/fc"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="#+id/fcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/saveBTN"
android:text="#string/save"
android:layout_width="wrap_content"
android:layout_height="60px" >
</Button>
<Button
android:id="#+id/cancelBTN"
android:text="#string/cancel"
android:layout_width="wrap_content"
android:layout_height="60px" >
</Button>
</LinearLayout>
</LinearLayout>

add change lister to both edit text
priceEdit.addTextChangedListener(mCostChangeWatcher);
pumpEdit.addTextChangedListener(mCostChangeWatcher);
TextWatcher mCostChangeWatcher = new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
if(!TextUtils.isEmpty(priceEdit.getText()) && !TextUtils.isEmpty(pumpEdit.getText())){
costEdit.setText(calculateCost(priceEdit.getText(), pumpEdit.getText()));
}
}
};

Related

Input dialog doesn't take right value ,

I'm trying to make a spreadsheat, but I face a problem - I get a "reandom" result returned by the dialog box.
my XML file:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="30dp"
android:background="#FFFFFF">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#020202"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="0dp">
<TextView
android:id="#+id/titleR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="prod price"
android:background="#android:color/white"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="1dp"/>
<TextView
android:id="#+id/titleQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Quantité"
android:background="#android:color/white"
android:layout_marginHorizontal="0dp"
android:layout_marginVertical="1dp"/>
<TextView
android:id="#+id/titleT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Totale"
android:background="#android:color/white"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="1dp"/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="0dp"
android:background="#020202"
android:baselineAligned="false"
>
<TextView
android:id="#+id/r5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginHorizontal="1dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:text="v 5 usd"
/>
<EditText
android:id="#+id/q5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginHorizontal="0dp"
android:layout_marginVertical="0dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:inputType="numberDecimal"
android:maxLength="5"
android:maxLines="1"
android:text="0"
/>
<TextView
android:id="#+id/t5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="0dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:text=""/>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="1dp"
android:layout_marginVertical="0dp"
android:background="#020202"
>
<TextView
android:layout_marginTop="1dp"
android:id="#+id/myprc"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/white"
android:layout_marginBottom="1dp"
android:layout_marginHorizontal="1dp"
android:text="Pourcentage"
android:gravity="center"
android:onClick="onClick"
></TextView>
<TextView
android:layout_marginTop="1dp"
android:id="#+id/prcc"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginHorizontal="0dp"
android:layout_marginBottom="1dp"
android:layout_weight="1"
android:autoText="false"
android:background="#android:color/white"
android:clickable="true"
android:gravity="center"
android:inputType="text"
android:maxLength="2"
android:maxLines="1"
android:text="6%"></TextView>
><TextView
android:layout_marginTop="1dp"
android:id="#+id/prcT"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:background="#android:color/white"
android:layout_marginBottom="1dp"
android:layout_marginHorizontal="1dp"
></TextView>
</TableRow>
</TableLayout>
</RelativeLayout>
my java code:
package com.example.mcalc;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.text.DecimalFormat;
public class MainActivity extends AppCompatActivity {
TextView myprc;
EditText q5;
TextView t5;
TextView t50;
TextView prcc;// cel
TextView prcT;
double prc1;
DecimalFormat tst = new DecimalFormat(" #,0.00 '%'");
EditText input;// dilog input
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabble);
myprc = (TextView)findViewById(R.id.myprc);
q5 = (EditText) findViewById(R.id.q5);
t5 = (TextView) findViewById(R.id.t5);
t50 = (TextView) findViewById(R.id.t50);
prcc = (TextView) findViewById(R.id.prcc) ;//cel
prcT = (TextView) findViewById(R.id.prcT);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pourcentage");
builder.setMessage("Merci d entrer le %");
input=new EditText(this);
builder.setView(input);
////
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
prc1 = Double.parseDouble(input.getText().toString());
String str;
str= String.valueOf(((Double) prc1));
prcc.setText(str+"%");
}
});
final AlertDialog ad = builder.create();
//Click listener Pourcentage %
myprc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ad.show();
}
});
q5.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
double tq5;
if ((q5.getText().length() == 0)) {
t5.setText("");
} else {
tq5 = (Double.valueOf(q5.getText().toString())*5) -
(Double.valueOf(q5.getText().toString())*5*prc1);
t5.setText(""+tq5);
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
prcc.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
double prc;
if ((prcc.getText().length() == 0)) {
prcT.setText("");
} else {
prcT.setText("blabla");
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
}

Spinner in ListView seems to appears outside of ListView

I am now developing a App which has a spinner in ListView.
It seems for me that spinner appuears outside of Listview.
What causes the problem ?
The window is as follows: (See 2 Red Circles)
Problem(Red Circle)
My MainActivity.xml is as follows :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainView"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayoutButton">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_camera"
android:id="#+id/buttonCapture" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_receipt"
android:id="#+id/buttonSelect"
android:layout_toEndOf="#+id/buttonCapture"
android:layout_marginStart="20dp" />
</RelativeLayout>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/switchAddSelection"
android:text="#string/addSelection"
android:textSize="20sp"
android:gravity="end"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textViewDate"
android:textSize="20sp"
android:layout_below="#+id/relativeLayoutButton"
android:layout_centerHorizontal="true"/>
<ListView
android:id="#+id/listViewBoughtItems"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/buttonSave"
android:layout_below="#+id/textViewDate" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonSave"
android:src="#drawable/ic_database"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
My List Item xml os as follows:
<?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="horizontal">
<TextView
android:layout_width="30dp"
android:layout_height="wrap_content"
android:id="#+id/textViewNumber"
android:textSize="14sp"
android:gravity="end"
android:layout_centerVertical="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editTextItem"
android:inputType="textMultiLine"
android:textSize="14sp"
android:layout_toEndOf="#+id/textViewNumber"
android:layout_toStartOf="#+id/buttonDelete"
android:layout_marginStart="10dp"/>
<Spinner
android:id="#+id/spinnerCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextItem"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/textViewNumber" />
<TextView
android:id="#+id/textViewCurrencySymbol"
android:layout_width="20dp"
android:layout_height="40dp"
android:layout_below="#+id/editTextItem"
android:layout_toStartOf="#+id/editTextPrice"
android:gravity="end|center_vertical"
android:textSize="14sp" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/editTextPrice"
android:singleLine="true"
android:gravity="end"
android:inputType="numberDecimal"
android:textSize="14sp"
android:layout_toStartOf="#+id/buttonDelete"
android:layout_below="#+id/editTextItem"/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/buttonDelete"
android:background="#drawable/ic_cancel_red_24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"/>
</RelativeLayout>
My code concerning spinner is as follows :
public View getView(final int position, View convertView, #NonNull ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.bought_list_item, null);
}
final ItemBean item = this.getItem(position);
if (item != null) {
TextView mNumber = convertView.findViewById(R.id.textViewNumber);
mNumber.setText(String.valueOf(position + 1));
mBoughtItem = convertView.findViewById(R.id.editTextItem);
mBoughtItem.setText(item.getBoughtItem());
mBoughtItem.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
gReceipt.boughtItemList.get(position).description = mBoughtItem.getText().toString();
}
});
TextView mCurrencySymbol = convertView.findViewById(R.id.textViewCurrencySymbol);
mCurrencySymbol.setText(R.string.currencySymbol);
mPrice = convertView.findViewById(R.id.editTextPrice);
mPrice.setText(String.format(Locale.JAPANESE, "%.1f", item.getPrice()));
mPrice.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
gReceipt.boughtItemList.get(position).price = Float.valueOf(mPrice.getText().toString());
}
});
mSpinner = convertView.findViewById(R.id.spinnerCategory);
ArrayAdapter<String> adapterCategory = new ArrayAdapter<>(thisContext, android.R.layout.simple_spinner_item);
adapterCategory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapterCategory.add("AAA");
adapterCategory.add("BBB");
adapterCategory.add("CCC");
mSpinner.setAdapter(adapterCategory);
}
return convertView;
}
}
P.S.
This phenomenon occurs on Scrolling ListView.
I am appreciated any advise.
Thank you in advance.
That's wired problem! try this and check it's ok or not
<ListView
android:id="#+id/listViewBoughtItems"
android:layout_width="match_parent"
android:layout_height="wrap_content" //change this line from match_parent to wrap_content
android:layout_above="#+id/buttonSave"
android:layout_below="#+id/textViewDate" />

How can I get this custom view to show?

I'm having problems getting this view just to show up. When I go to the screen that should have the view nothing happens in the view Here are the relevant files:
CreateTimerActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_timer);
final Context context = this;
mVisible = true;
mControlsView = findViewById(R.id.create_timer_content_controls);
mContentView = findViewById(R.id.create_timer_content);
// Set up the user interaction to manually show or hide the system UI.
mContentView.setOnClickListener((View view) -> {
toggle();
});
/*XmlPullParser parser = getResources().getXml(R.id.view_tim);
AttributeSet attributes = Xml.asAttributeSet(parser);*/
final TableLayout tableLayout = (TableLayout) findViewById(R.id.create_timer_table);
TimerFormView timerFormView = new TimerFormView(context, tableLayout);
timerFormView.initializeComponents();
}
TimerFormView.java
public class TimerFormView extends TableLayout {
private Context context;
private final ContentValues timerValues;
private final ContentValues timerSegmentValues;
private final TableLayout tableLayout;
public TimerFormView(Context context, TableLayout tableLayout) {
this(context, null, tableLayout);
}
public TimerFormView(Context context, AttributeSet attrs, TableLayout tableLayout) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.TimerFormView, 0, 0);
String titleText = "Hello";
#SuppressWarnings("ResourceAsColor")
int valueColor = a.getColor(0,
android.R.color.holo_blue_light);
a.recycle();
this.context = context;
this.tableLayout = tableLayout;
TimerDatabase timerDatabase = new TimerDatabase(context);
SQLiteDatabase databaseHelper = timerDatabase.getWritableDatabase();
timerValues = new ContentValues();
timerValues.put(TimerDatabase.TimerEntry.COLUMN_NAME_TIMER_NAME, "");
timerSegmentValues = new ContentValues();
}
public TimerFormView(Context context, AttributeSet attrs)
{
this(context, attrs, null);
}
public void initializeComponents() {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_timer_form, this, true);
final TextView timerNameTextView = (TextView) findViewById(R.id.timerNameTxt);
timerNameTextView.setSingleLine(true);
InputFilter[] filterArrayTimerName = new InputFilter[1];
filterArrayTimerName[0] = new InputFilter.LengthFilter(32);
timerNameTextView.setFilters(filterArrayTimerName);
final Button saveTimerBtn = (Button) findViewById(R.id.saveTimerBtn);
saveTimerBtn.setEnabled(false);
saveTimerBtn.setOnClickListener((View v) -> {
timerValues.put(TimerDatabase.TimerEntry.COLUMN_NAME_TIMER_NAME, timerNameTextView.getText().toString());
});
// Enable the timer to be saved once text is entered
TextWatcher timerNameTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s){
if(s.length() > 0) {
saveTimerBtn.setEnabled(true);
} else {
saveTimerBtn.setEnabled(false);
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){
// you can check for enter key here
}
public void onTextChanged (CharSequence s, int start, int before,int count) {
}
};
EditText timerNameEditText = (EditText) findViewById(R.id.timerNameTxt);
timerNameEditText.addTextChangedListener(timerNameTextWatcher);
// Segments
final TextView segmentNameTextView = (TextView) findViewById(R.id.segmentNameTxt);
segmentNameTextView.setSingleLine(true);
InputFilter[] filterArraySegmentName = new InputFilter[1];
filterArraySegmentName[0] = new InputFilter.LengthFilter(32);
segmentNameTextView.setFilters(filterArraySegmentName);
Button addSegmentBtn = (Button) findViewById(R.id.addSegmentBtn);
addSegmentBtn.setEnabled(false);
addSegmentBtn.setOnClickListener((View v) -> {
// Content for the new segment
TableRow segmentTableRow = new TableRow(context);
segmentNameTextView.setText(segmentNameTextView.getText());
segmentTableRow.addView(segmentNameTextView);
tableLayout.addView(segmentTableRow);
timerSegmentValues.put(TimerDatabase.TimerSegment.COLUMN_NAME_SEGMENT_NAME, segmentNameTextView.getText().toString());
});
TextWatcher segmentNameTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s){
if(s.length() > 0) {
saveTimerBtn.setEnabled(true);
} else {
saveTimerBtn.setEnabled(false);
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){
// you can check for enter key here
}
public void onTextChanged (CharSequence s, int start, int before,int count) {
}
};
EditText segmentNameEditText = (EditText) findViewById(R.id.segmentNameTxt);
segmentNameEditText.addTextChangedListener(segmentNameTextWatcher);
EditText segmentDurationEditText = (EditText) findViewById(R.id.segmentDurationTxt);
//segmentDurationEditText.addTextChangedListener(segmentTextWatcher);
EditText segmentRepeatEditText = (EditText) findViewById(R.id.segmentRepeatTxt);
//segmentRepeatEditText.addTextChangedListener(segmentTextWatcher);
setVisibility(View.VISIBLE);
super.layout(50, 50, 50, 50);
setOrientation(LinearLayout.HORIZONTAL);
setGravity(Gravity.CENTER_VERTICAL);
}
}
view_timer_form.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp" android:layout_height="400dp">
<TableRow android:layout_width="400dp" android:layout_height="400dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Create Timer"
android:id="#+id/createTimerLbl" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Timer Name"
android:id="#+id/timerNameLbl"
android:gravity="top" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/timerNameTxt"
android:layout_column="1" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/addSegmentNameRow">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Segment Name"
android:id="#+id/segmentNameLbl"
android:gravity="top" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/segmentNameTxt"
android:layout_column="1" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Duration"
android:id="#+id/segmentDurationLbl"
android:gravity="top" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/segmentDurationTxt"
android:inputType="number"
android:layout_column="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Seconds"
android:id="#+id/durationSecondsLbl"
android:gravity="top" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Repeat"
android:id="#+id/segmentRepeatLbl"
android:gravity="top" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/segmentRepeatTxt"
android:inputType="number"
android:layout_column="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Times"
android:id="#+id/segmentRepeatTimesLbl"
android:gravity="top" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/addSegmentBtnRow">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Segment"
android:id="#+id/addSegmentBtn" />
</TableRow>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Timer"
android:id="#+id/saveTimerBtn" />
</TableRow>
</TableLayout>
activity_create_timer.xml
<FrameLayout 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"
android:background="#0099cc"
tools:context="com.example.timer.CreateTimerActivity">
<TextView android:id="#+id/create_timer_content" android:layout_width="match_parent"
android:layout_height="match_parent" android:keepScreenOn="true" android:textColor="#33b5e5"
android:textStyle="bold" android:textSize="50sp" android:gravity="center"
android:text="" />
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/create_timer_content_controls"
style="?metaButtonBarStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
tools:ignore="UselessParent">
<com.example.timer.views.TimerFormView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/create_timer_table">
</com.example.timer.views.TimerFormView>
</LinearLayout>
</FrameLayout>
</FrameLayout>
I had such issue and I solved it in this ways...
Don't call any instance of customView or even static vars from activity.
only define constructor with (Context, Attributes)
and initialize everything you want inside customView class.
Good luck

Focus changes to listview once i clear the Edittext

I'm using broadcast receiver to show a dialog.So the flow of code is something like:
Step1 Getting the requestCode value
Step2 Based on this requestCode the broadCast receiver goes to if or else if or else part
Step3 If the value that i entered using some scanner into the EditText(i.e Scan) doesn't matches it shows a Toast "Item Not Available".
Step 4 Once "Item Not Available" toast comes the focus changes to the Listview which is my problem.
Step5 Again if i pass value to the Scan EditText the Listview get click automatically.
So my question is "How to remove focus from the Listview" and set it to the EditText(i.e Scan).
For Reference I'm attaching the snap with code snippet and the layout.xml.Please have a look and drop your suggestions why the focus is going to the listview.
.java snippet
final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
loc = mspinner.getItemAtPosition(mspinner.getSelectedItemPosition())
.toString();
final String ItemNo;
final String Desc;
final String StockUnit;
final String PickSeq;
final String qtyCount;
final String qtyonHand;
final Button mok;
final Button mcancel;
final Button mplus;
final Button mminus;
final EditText medtQtyCount;
final EditText medtItem;
final EditText medtdesc;
final EditText medtuom;
final DatabaseHandler dbHandler;
final String[] UOM = null;
int requestCode;
LayoutInflater li = LayoutInflater.from(InventoryCount.this);
View promptsView = li.inflate(R.layout.quantityupdate, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
InventoryCount.this);
alertDialogBuilder.setView(promptsView);
//requestCode=Integer.parseInt(intent.getStringExtra("idx"));
requestCode=intent.getIntExtra("idx", -1);
// create alert dialog
final AlertDialog alertDialog = alertDialogBuilder.create();
dbHandler = new DatabaseHandler(InventoryCount.this);
medtuom = (EditText) promptsView.findViewById(R.id.edt_mseshipuom_mic);
mok = (Button) promptsView.findViewById(R.id.btn_mseshipOk_mic);
mcancel = (Button) promptsView.findViewById(R.id.btn_mseshipCancel_mic);
mplus = (Button) promptsView.findViewById(R.id.btn_mseshipIncr_mic);
mminus = (Button) promptsView.findViewById(R.id.btn_mseshipDecr_mic);
medtQtyCount = (EditText) promptsView
.findViewById(R.id.edt_shipShiped_mic);
medtdesc = (EditText) promptsView
.findViewById(R.id.edt_mseshipQtyOrd_mic);
medtItem = (EditText) promptsView
.findViewById(R.id.edt_mseshipItemNo_mic);
if (requestCode == 1) {
}
else if (requestCode == 0) {
// ItemNo
/*if (resultCode == RESULT_OK) {
Log.i("Scan resul format: ",
intent.getStringExtra("SCAN_RESULT_FORMAT"));
*/
String itNo = intent.getStringExtra("SCAN_RESULT");
dbhelper.getReadableDatabase();
MIC_Inventory mic_inventory = dbhelper.getMicInventoryDetails(
loc, itNo);
dbhelper.closeDatabase();
if (mic_inventory != null) {
loc = mspinner.getItemAtPosition(
mspinner.getSelectedItemPosition()).toString();
ItemNo = mic_inventory.getItemno();
Desc = mic_inventory.getItemdescription();
PickSeq = mic_inventory.getPickingseq();
StockUnit = mic_inventory.getStockunit();
qtyonHand = mic_inventory.getQoh();// This value gives
// QOHand
qtyCount = mic_inventory.getQc();
medtItem.setText(ItemNo);
medtdesc.setText(Desc);
medtQtyCount.setText(qtyCount);
medtuom.setText(StockUnit);
mplus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String a = medtQtyCount.getText().toString();
int b = Integer.parseInt(a);
b = b + 1;
a = a.valueOf(b);
medtQtyCount.setText(a);
}
});
mminus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int c = Integer.parseInt(medtQtyCount.getText()
.toString());
c = c - 1;
medtQtyCount.setText(new Integer(c).toString());
}
});
mok.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
/*
* UOM[mspinnerUom.getSelectedItemPosition()] =
* medtQtyCount .getText().toString();
*/
MIC_UOMInternal mic_uom = new MIC_UOMInternal();
mic_uom.setLocation(loc);
mic_uom.setItemno(ItemNo);
String updatedqtyCount = medtQtyCount.getText()
.toString();
if (!qtyCount.equals(updatedqtyCount)) {
mic_uom.setQc(Double
.parseDouble(updatedqtyCount));
mic_uom.setUom(StockUnit);
MIC_Inventory mic_Inventory = new MIC_Inventory();
mic_Inventory.setItemdescription(Desc);
mic_Inventory.setItemno(ItemNo);
mic_Inventory.setLocation(loc);
mic_Inventory.setPickingseq(PickSeq);
mic_Inventory.setQc(updatedqtyCount);
mic_Inventory.setQoh(qtyonHand);
mic_Inventory.setStockunit(StockUnit);
dbHandler.getWritableDatabase();
String result = dbHandler
.insertIntoInternal(mic_uom);
if (result.equals("success")) {
result = dbHandler.updateMIC(mic_Inventory);
}
dbHandler.closeDatabase();
}
Intent i = new Intent(InventoryCount.this,
InventoryCount.class);
i.putExtra("et", 1);
i.putExtra("LOCATION", loc);
// i.putExtra("ID", ID);
startActivity(i);
// InventoryCount.this.finish();
}
});
mcancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.cancel();
}
});
// show it
alertDialog.show();
} else {
/*
* Toast.makeText(this, "Item not available",
* Toast.LENGTH_LONG).show();
*/
toastText.setText("Item not available");
Toast toast = new Toast(getBaseContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 410);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(toastLayout);
toast.show();
msearchtext.setText("");
/*msearchtext.setFocusableInTouchMode(true);
msearchtext.requestFocus();*/
/*msearchtext.setSelection(0);
lstView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
*/msearchtext.requestFocus();
}
else if (requestCode == 2) {
}
else
{
toastText.setText("Problem in Scanning");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 410);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(toastLayout);
toast.show();
}
}
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"
android:background="#drawable/border_green"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/txt_InvTitle"
style="#style/pageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="#string/invTitle" />
<View
android:id="#+id/txt_InvView"
android:layout_width="match_parent"
android:layout_height="2dip"
android:layout_below="#+id/txt_InvTitle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#2E9AFE" />
<LinearLayout
android:id="#+id/invLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/txt_InvView"
android:layout_marginTop="16dp" >
<TextView
android:id="#+id/txtLoc"
style="#style/textRegular"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center"
android:text="#string/location" />
<Spinner
android:id="#+id/sploc"
style="#style/SpinnerItemAppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:editable="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/invScanType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/invLocation"
android:layout_gravity="center"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="18dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/edt_Search_mic"
style="#style/EditTextAppTheme_Scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_weight=".15"
android:gravity="center"
android:hint="#string/scan" />
<RadioGroup
android:id="#+id/radioScanBasedOn_mic"
style="#style/RadioButtonAppTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radioInum_mic"
style="#style/textRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:button="#drawable/radiobutton_selector"
android:checked="true"
android:drawablePadding="50dp"
android:paddingLeft="10dip"
android:text="#string/itemno" />
<RadioButton
android:id="#+id/radioNum_mic"
style="#style/textRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:button="#drawable/radiobutton_selector"
android:checked="false"
android:layout_marginRight="5dp"
android:layout_weight=".25"
android:drawablePadding="50dp"
android:paddingLeft="10dip"
android:text="#string/manfno" />
<RadioButton
android:id="#+id/radioUpc_mic"
style="#style/textRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:button="#drawable/radiobutton_selector"
android:checked="false"
android:layout_marginRight="5dp"
android:layout_weight=".25"
android:drawablePadding="50dp"
android:paddingLeft="10dip"
android:text="#string/upc" />
</RadioGroup>
</LinearLayout>
<HorizontalScrollView
android:id="#+id/scroll_full_mic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/invScanType" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="25dp"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lay_fullTitle_mic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
style="#style/textRegular_list"
android:layout_width="105dp"
android:layout_height="wrap_content"
android:text="#string/itemno"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
style="#style/textRegular_list"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:gravity="center|left"
android:text="#string/description"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
style="#style/textRegular_list"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="center|left"
android:text="#string/pick_seq"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
style="#style/textRegular_list"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="center|left"
android:text="#string/qoh"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
style="#style/textRegular_list"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="center|left"
android:text="#string/qc"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
<TextView
style="#style/textRegular_list"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="center|left"
android:text="#string/uom"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/lst_msefull_mic"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/ListViewAppTheme.White" >
</ListView>
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:id="#+id/lay_PO_mic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="41dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="gone" >
<Button
android:id="#+id/btn_OrderLstImport_mic"
android:layout_width="100dp"
android:layout_height="100dp"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/btn_OrderLstExport_mic"
android:layout_width="100dp"
android:layout_height="100dp"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/btn_OrderLstExit_mic"
android:layout_width="100dp"
android:layout_height="100dp"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
Add a textwatcher to edit text and check when text is not blank and it is not equal to expected text then only switch the focus.
/* Set Text Watcher listener */
yourEditText.addTextChangedListener(passwordWatcher);
and check for text once user enter text
private final TextWatcher passwordWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
if (s.length() != 0 && passwordEditText.getText().equals("Your expected text")) {
// show your toast and change focus
}
}
}
You should make your listview not focusable by using setFocusable(false) when not required and when you get response correctly from barcode scanner then you can again make your listview focusable.

by clicking on TextView i want to see the list of items

In my android application, i want to display a list of items when i click on a Textview, it display a list of items and i can add and delete items from that list. how can i do it through java code
Kindly guide. i will be very thankful to you
my code is:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cus_name"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:onClick="onClick"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/cus_name_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/contact_no"
android:clickable="true"
android:focusable="true"
android:onClick="onClick"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/contact_no_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ticket_no"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/ticket_no_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="#string/task_detail"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/task_detail_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>
If I understood right I would suggest extending a Dialog to make custom dialog that pops out whenever user clicks on TextView (as included in Imran Khan's answer). This dialog would contain ListView and whatever else you need for handling the list. Example of such approach as I used it some time ago:
public class LogOverlay extends Dialog{
private Server mItem;
private boolean end=false;
private int mLimitHigh = 15;
private int mLimitLow = 0;
private ListView mListView;
private LogListAdapter mAdapter;
private ArrayList<LogUnit> mLog = new ArrayList<LogUnit>();
private boolean mScroll;
private Context context;
ProgressDialog pd;
public LogOverlay(Context context,Session session,Server server) {
super(context);
this.setContentView(R.layout.overlay_logs);
mListView=(ListView) this.findViewById(R.id.log_list);
mAdapter = new LogListAdapter(context, new ArrayList<LogUnit>(), new String[] {});
mListView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
mListView.setDividerHeight(1);
mListView.setAdapter(mAdapter);
mListView.setOnScrollListener(new OnScrollListener() {
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
....
}
}
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
});
}

Categories