Recyclerview scroll to empty Edit Text - android

I am using Edit text as a view of android Recycler view but, when a user does not enter any value in Edit text then I am not able to show an Error message or auto scroll on that empty Edit text. I am storing some data into the database using recycler view edit text, I searched very much but I didn't found any helping material. I want to submit that recycler view data before validating all fields (Edit text).

Solved.
int counter = 0;
for(int i=0;i<stockData.length;i++) {
for (int j = 0; j < stockData[i].length; j++) {
if((stockData[i][0]==null || stockData[i][0].matches("")) ||
((stockData[i][1]==null || stockData[i][1].matches("")) ||
(stockData[i][4]==null || stockData[i][4].matches("Stock"))))
{
counter++;
//Log.d(Constants.TAG,"sale is empty and index is "+i);
mPromoter_recyclerView.scrollToPosition(i);
break;
}
}
if(counter>0)
break;
}

Related

MultiSelect List View not detecting unchecked fields on android

I have a multiSelec listView fills with days. I´m getting the items selected, my problem is when I click in one list field in order to unselect it. An example:
I check the position 1,2,3,4,5 on the list and after that I uncheck the 4,5 position , so finally I have 3 fields checked.
With my code I get 5 values checked instead 3 .
¿Can anyone help me?
What I'm doing wrong?
private void gettingDaysChecked(){
boolean isSomethingChecked = false;
SparseBooleanArray checked = mListView.getCheckedItemPositions();
Log.d(Constants.TAG,"cheched size is "+checked.size() );
if (checked.size()>0)
isSomethingChecked=true;
if (isSomethingChecked) {
for (int i = 0; i < checked.size(); i++) {
int positionItem = checked.keyAt(i);
Log.d(Constants.TAG, "in position" + positionItem);
localList.add(positionItem);
}
app.setDaysCheckedFilterPeriod(localList);
}else if(!isSomethingChecked){
Log.d(Constants.TAG,"nothing checked ");
}
}

Selecting/Unselecting all items in a Listview

I am using a multi select listview in my application. Specifically the simple_list_item_activated_1.
I have some of code, a button, that will select all the listview items. I have some logic saying that if all the items are already selected then deselect all the items.
When I press the button the first time, it will select all the items in the list as expected. and when I press the button a second time it deselects all the items as expected.
Here is my problem:
When I press the button for a third time "selectedCount" still equals "childCount". So obviously my code will never enter the If statement.
Would anyone know why this is happening? or maybe there is a better way to do what im trying to achieve?
int childCount = officerList.getChildCount();
int selectedCount = officerList.getCheckedItemPositions().size();
if(childCount != selectedCount){
for (int i = 0; i < officerList.getChildCount(); i++) {
officerList.setItemChecked(i, true);
}
}else{
for (int i = 0; i < officerList.getChildCount(); i++) {
officerList.setItemChecked(i, false);
}
}
}
Try this logic, it will check all the items if none of the items are checked, else will check only the items which are unchecked and vice versa.
public void onClick(View v) {
SparseBooleanArray sparseBooleanArray = officerList.getCheckedItemPositions();
if(sparseBooleanArray != null && sparseBooleanArray.size() >0) {
for (int index = 0; index < sparseBooleanArray.size(); index++) {
if(sparseBooleanArray.valueAt(index)){
officerList.setItemChecked(sparseBooleanArray.keyAt(index),true);
}
else {
officerList.setItemChecked(sparseBooleanArray.keyAt(index),false);
}
}
}
else {
for (int index = 0; index < officerList.getCount(); index++) {
officerList.setItemChecked(index,true);
}
}
}
I managed to answer my own question. Using getCheckItemPositions().size() is an unreliable way of achieving what I want.
This will return a sparseBooleanArray() of all Items checked, so the first time it works correctly as initially there is nothing selected so it will return 0. Then once everything is selected the sparseBooleanArray will be equal to all the items in the list as they were all selected.
However as I learned spareBooleanArray is an Array that stores the position and a Boolean flag of if it is selected or not. In my scenario when I press the select all button for the third, the size of the array is still equal to number of list items.
How I have fixed my issue, is to use getCheckedItemCount() which only returns the number of selected items as I originally wanted. hopefully this answer will help someone else.
int childCount = officerList.getChildCount();
int selectedCount = officerList.getCheckedItemCount();
if(childCount != selectedCount){
for (int i = 0; i < officerList.getChildCount(); i++) {
officerList.setItemChecked(i, true);
}
}else{
for (int i = 0; i < officerList.getChildCount(); i++) {
officerList.setItemChecked(i, false);
}
}
}

Get the text of the textView selected using Robotium

I am automating a product using robotium. I need to do some dat validation kind of task there.
Scenario is like:
We click on a list, select some items in the list and do some operation.
I want to put the names of the items selected into an array. Such that i can compare it later.
I used the following code:
for(i=0; i<=n;i++)
{
solo.clickInList(i);
Array1[i]=solo.getText(i).toString();
}
But sadly, this statement is not extracting the text of the textView selected but the id of the textView.
Please help me by giving an example of how to get the text of the TextView selected.
At a fix!!
if you have only listview with texts, it should work for you (I didn't test it):
ListView listView = solo.getView(ListView.class, 0);
String text = listView.getItemAtPosition(position));
Another way will be like this:
ArrayList<TextView> result = solo.clickInList(line);
String text = "";
for (int i = 0; i < result.size(); i++) {
text += result.get(i).getText().toString() + " ";
}
if (text.length() > 0) {
text = text.substring(0, text.length() - 1); // remove last space
}

How to identify items in a logical way?

I am new to Android development and I am trying to handle clicks on a grid of items. What is the best way to do that? So far I have something like this to set the onclicklistener:
TableLayout layout = (TableLayout) findViewById(R.id.tableLayout1);
for (int i = 0; i < layout.getChildCount(); i++) {
View v = layout.getChildAt(i);
if (v instanceof TableRow) {
for (int j = 0; j < ((TableRow)v).getChildCount(); j++) {
View v2 = ((TableRow)v).getChildAt(j);
v2.setOnClickListener(this);
}
}
}
Now I want to handle the clicks on the items contained in the table. As there are many items I want to avoid writing a long "switch". The items have logical IDs containing the number of the row and the column. Is there a way to get the actual ID of the item that has been clicked (the ID in the XML) and then parse it? If not, what would be the solution.
Thanks
You have a few options. You can set the onClickListener inline:
v2.setOnClickListener(new OnClickListener() {
public void onClick (View viewClicked) {
Log.d("View row: " + i + ", column: " + j);
// or something else
}
});
Or you can use the View.setTag(), which will allow you to store key-value pairs to the view, similar to a map.

Dynamically add page numbers in android

I am stuck with an issue in my project.The need is to show all data fetched from server using webservices.I successfully get data from server using json.but i want to show data on screen in tabular format 50 records at a time.Please suggest me how to do this or if you can guide me through a better way to implement paging in android.
The code of paging is here :
Implement Pagination on tab layout
and the function i use to append rows dynamically to tablelayout is :
private void appendRows(TableLayout table, String[] data) {
int rowSize = data.length;
int colSize = (data.length > 0) ? 1 : 0;
for (int i = 0; i < rowSize; i++) {
TableRow row = new TableRow(this);
for (int j = 0; j < colSize; j++) {
String[] rowVal = null;
rowVal = data[i].split(",");
for (int k = 0; k <= rowVal.length - 1; k++) {
TextView c = new TextView(this);
c.setText(rowVal[k]);
c.setTextColor(getResources().getColor(R.color.white));
c.setPadding(3, 3, 3, 3);
row.addView(c);
}
}
table.addView(row, new TableLayout.LayoutParams());
}
}
Please guide me I need to show hyperlink page numbers at the bottom of my window as shown in google
This might be of some help. Its a tutorial for pagination. Here is the source code.
I have had similar requirement like yours and I normally use the listview for it. Due to the recycling of views it is a lot more efficient than using a table layout.
You can create a custom adapter where you always return the size as 50+1, 100+1. So in your onItemClickListener you can check if the row position is more than the items, if so, then you add the next 50 items to the adapter. This is a basic idea of how to do it.

Categories

Resources