Get first argument in live-template - android

Recently i was creating my own live-template, i was customizing for loop, here is how default for loop is given in live-template.
for(int $INDEX$ = 0; $INDEX$ < $LIMIT$; $INDEX$++) {
$END$
}
but i want my method's first argument inplace of $LIMIT$, how can i do that?
public void getList(ArrayList<String> list)
{
}
then my for loop shoulde be
for(int i = 0; i < list.size; i++) {
...
}
I have seen template of logm, but it is printing all arguments of method
groovyScript("'\"' + _1.collect { it + ' = [\" + ' + it + ' + \"]'}.join(', ') + '\"'", methodParameters())

You can add the following live template:
for(int $INDEX$ = 0; $INDEX$ < $VAR$.size(); $INDEX$++){
$END$
}
Then go to right button "Edit variables" and put the following predefined methods in the expressions fields:
You can find all predefined methods in Jetbrains documentation

Related

unable to retrieve values from two different arraylist

i am having two different arraylist of diffrent size,my problem is that i have to retrieve values from both the list and show that on to a textview,when i am using two loops it is first completing the inner loop and than executing outer loop and the vales are getting printed two times and if using break to break the inner loop it is completely ignoring inner loop after 1st loop.
ArrayList<LocationDto>location = new ArrayList<>();
education<EducationDto> = new ArrayList<>();
if (education.size() != 0) {
for (int j = 0; j < education.size(); j++) {
for (int k = 0; k < location.size(); k++) {
if (!education.get(j).getSpecializationTitle().equalsIgnoreCase("") && !location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + "(" + education.get(j).getSpecializationTitle() + ")" + " Located at " + location.get(k).getLocationName());
} else if (education.get(j).getSpecializationTitle().equalsIgnoreCase("") && !location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + " Located at " + location.get(j).getLocationName());
} else if (!education.get(j).getSpecializationTitle().equalsIgnoreCase("") && location.get(k).getLocationName().equalsIgnoreCase("")) {
tvEducation.append(education.get(j).getEducationTitle() + "(" + education.get(j).getSpecializationTitle() + ")");
} else {
tvEducation.append(education.get(j).getEducationTitle());
}
if (j != education.size() - 1) {
tvEducation.append(" , ");
}
break;
}
}
} else {
tvEducation.setText("Not Specified");
tvEducation.setTextColor(getResources().getColor(R.color.color_three));
}
what should i do now?
The break statement terminates a loop regardless of whether it has completed or not, so your problem is that you've put a break directly inside your inner for loop without some sort of condition. Therefore the first time the loop runs it will reach the break which is why it's terminating on the first iteration!
You probably mean to put the break inside the last if statement?

How to check pdf files from mobile storage and list the name by consensus with dynamic list view

I have dynamic listView linked with JSONArray, in the adapter i'm trying to read the storage to check if the pdf file is downloaded already the Button text will be View and will call View method but if the the file not there the Button text will be Download and will call Download method.
I have been trying this code but it's not work
String path2 = Environment.getExternalStorageDirectory() + "/materialpdffolder/";
File path = new File(path2);
File list[] = path.listFiles();
for( int i=0; i < materialList.size() ; i++)
{
for( int x=0; x <= list.length ; x++) {
if (list[x].getName() != null) {
if (list[x].getName().equals(materialList.get(position).getMaterial_file_name().toString())) {
DVmaterial.setText("View(" + materialList.get(position).getMaterial_file_name().toString() +")" );
}}else
{
DVmaterial.setText("Download(" + materialList.get(position).getMaterial_file_name().toString() + ")");
}
}
}
The problem is when there’s no file, the application is stack and give error and not give any results for list[x].get Name() and when I use materiallist.size() for for looping it is doesn’tgive a correct answer
Try to change with this code
if (list[x].getName() != null) {
if (list[x].getName().equals(materialList.get(position).getMaterial_file_name().toString())) {
DVmaterial.setText("View(" + materialList.get(position).getMaterial_file_name().toString() +")" );
}else
{
DVmaterial.setText("Download(" + materialList.get(position).getMaterial_file_name().toString() + ")");
}
}
Remove one bracket from }}else and put it end of else

Which Json structure suitable for this work?

This function generate dummy data for this Structure .
private void createDummyData() {
for (int i = 1; i <= 10; i++) {
VerticalDataModel dm = new VerticalDataModel();
dm.setSectionTitle("Section " + i);
ArrayList<SingleItemModel> singleItem = new ArrayList<SingleItemModel>();
for (int j = 0; j <= 10; j++) {
singleItem.add(new SingleItemModel("Item " + j, "URL " + j));
}
dm.setSingleItemModelha(singleItem);
allSampleData.add(dm);
}
Know for generating this data from internet , i need json structor for this work .(I use volley library)
Thanks <3
{
data : [
{
"title":"section1",
"items":[{"name":"item1","url":"url1"},{"name":"item2","url":"url2"}]
},
{
"title":"section2",
"items":[{"name":"item3","url":"url3"},{"name":"item4","url":"url4"}]
}
]
}
so basically you have array of objects which contains title and items as its property. Again items is another array of objects which contains name and url as its property.

Passing String Array to A Robotium Class

I am automating a product using Robotium. In a module I have to validate the data derived.
For that I am using this code:
class sharefirstlevel {
public void A {
for(int k=1;k<=4;k+=2) {
ExpectedResult = solo.clickInList(k);
for (int i = 0; i < ExpectedResult.size(); i++) {
Actualvalues[i] += ExpectedResult.get(i).getText().toString() + " ";
solo.scrollListToLine(0, k);
ExpectedResult=solo.clickInList(1);
Actualvalues[i] += ExpectedResult.get(i).getText().toString() + " ";
ExpectedResult = solo.clickInList(2);
Actualvalues[i] += ExpectedResult.get(i).getText().toString() + " ";
Log.d("xyz","Values of the Strings are"+Actualvalues[i].toString());
}
}
}
}
Its extracting the values selected to an array.
Now when its derived, to validate I am using this code:
class sharedLevel {
public void B {
for(int i=0; i <= sharefirstlevel.Actualvalues.length; i++) {
Log.d("xyz","Values are:"+sharefirstlevel.Actualvalues[i]);
actual=solo.searchText(sharefirstlevel.Actualvalues[i]);
assertEquals(expected, actual);
Log.d("xyz","Values are:"+sharefirstlevel.Actualvalues[i]);
}
}
}
But the thing is in the first part of code proper values are extracted to the Array.
In the second part of code when I am passing the array values, I am not getting the values but the memory allocation object. Hence the test case is failing.
Please help me. Am at a fix !!
How about using
assertTrue(Arrays.equals(expected, actual));
EDIT: This answer is for the question for which the bounty was raised and not the edited question (https://stackoverflow.com/posts/18334315/revisions)
I solved the Problem. The change which I had to make in Class B was
for(int i=1;i<sharefirstlevel.Actualvalues.length;i++){
Log.d("Pratibha","Values are:"+sharefirstlevel.Actualvalues[i]);
actual=solo.searchText(sharefirstlevel.Actualvalues[i]);
assertEquals(expected, actual);
Log.d("TAG","Values are:"+sharefirstlevel.Actualvalues[i]);
}
And hence I am getting the values of the array in class B. Because the index started from 0, and I din't have any text values at 0th position, It was returning garbage values.
Thanks all for the responses.

android spell checking

I am trying to check the spelling of a word in code using the api's for ics.
I have used the spell checker sample as a starting point and using this I can get a list of suggested words based on the query word, however I can't see how just to check that the word is spelled correctly.
I have the code below from the example and using this I can see and check the suggestions but not the original word.
#Override
public void onGetSuggestions(final SuggestionsInfo[] arg0) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < arg0.length; ++i) {
// Returned suggestions are contained in SuggestionsInfo
final int len = arg0[i].getSuggestionsCount();
sb.append('\n');
for (int j = 0; j < len; ++j) {
sb.append("," + arg0[i].getSuggestionAt(j));
}
sb.append(" (" + len + ")");
}
runOnUiThread(new Runnable(){
#Override
public void run(){
if(arg0[0].getSuggestionsAttributes()==SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY){
mMainView.append(sb.toString());
}
}
});
}
I have added the if statement that checks for RESULT_ATTR_IN_THE_DICTIONARY but I don't know if this is checking the original word or the first suggestion. (If I enter 'ton' as a query I get 'ten' returned however if I enter 'twn' as a query I get no words returned)
What I really need is for either a correct word or empty string to be returned to a query.
Any help would be appreciated,
Thanks
for (int j = 0; j < len; ++j) {
if(arg0[i].getSuggestionAt(j).toString().contains(string)){
sb.append("," + arg0[i].getSuggestionAt(j));
Log.e("check if", ""+arg0[i].getSuggestionAt(j));
}else{
sb.append("" );
Log.e("check", ""+arg0[i].getSuggestionAt(j));
}
}
Try with this code
and also remove
if(arg0[0].getSuggestionsAttributes()==SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY){
mMainView.append(sb.toString());
}
if condition just put mMainView.append(sb.toString());
hope it's useful to you.

Categories

Resources