There might be an error in your code:
You are redefining finalCommodityValue
:
finalCommodityValue = 0;
if(argument < 26){
double finalCommodityValue = argument + 1.00;
}
Which is a compile-error since you cannot have more than one variable of the same name inside a function.
Now, if the variable finalCommodityValue
is defined outside of the function that contains the code you showed here, then you are shadowing it. This means that the finalCommodityValue
inside your if (argument < 26)
statement is different than the finalCommodityValue
you defined outside your whole function. It is, in a sense, hiding the value defined outside of your function.
Also, creating a variable inside the if
statement makes it exist only within the scope of the if
statement (between {}
). You are not using it for anything in your code.
I assume you didn't have the compile-error since you can debug how your code runs. That means finalCommodityValue
is defined as a class field. Thus, What you should do is remove double
:
finalCommodityValue = 0;
if(argument < 26){
finalCommodityValue = argument + 1.00;
}
Now, finalCommodityValue
in your function and within the if
statement corresponds to the same finalCommodityValue
defined globally in your class.
As far as why arg2
is always 0, I believe your problem is:
mCommCode = (AutoCompleteTextView) findViewById(R.id.CommCode);
You are using an OnItemClickListener
in an AutoCompleteTextView
. AutoCompleteTextView
is a TextView so it only has one item. That is why you are always getting position 0. You need to use a ListView
instead.
In you XML file you should have something like this:
<AutoCompleteTextView
android:id="@+id/tvAutocomplete"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:hint="@string/search_hint" >
<requestFocus />
</AutoCompleteTextView>
<ListView
android:id="@+id/lvDataList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="85" >
</ListView>
Further, create a class variable:
ListView searchList;
And in onCreate()
:
searchList = (ListView) findViewById(R.id.lvDataList);
Then in the function that contains the code you showed here, put an OnItemClickListener
on the ListView
and not on the AutoCompleteTextView
:
searchList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position,
long id) {
Log.d("POSITION", position);
// .. Rest of your code
}
});