[Q] Can't reference a non static method. - Android Q&A, Help & Troubleshooting

I hope this is the right place to ask this. The other sections seem to be more about discussion. I am running into one error that I have not encountered before and have tried quite a bit to find out what is going on.
AndroidStudio said:
Error: (109, 51) error: non-static method getAllContacts() cannot be referenced from a static context
Click to expand...
Click to collapse
Code:
// Class for dealing with the database
package com.testapplication.app;
import ...
public class DataBaseHandler extends SQLiteOpenHelper {
public List<Contact> getAllContacts() {
List<Contact> contListAdapt = new ArrayList<Contact>();
// Becomes non static in a static context if the method becomes static
SQLiteDatabase sql = getWritableDatabase();
Cursor cursor = sql.rawQuery("SELECT * FROM " + TABLE_CONTACTS, null);
if (cursor.moveToFirst()) {
do {
new Contact(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), Uri.parse(cursor.getString(5)));
} while (cursor.moveToNext());
}
cursor.close();
sql.close();
return contListAdapt;
}
}
Code:
// The main activity
package com.testapplication.app;
import ...
public class MainActivity extends ActionBarActivity {
List<Contact> contactListAdapter = new ArrayList<Contact>();
@Override
protected void onCreate (Bundle savedInstanceState) {
// There is a class called Contact
// FIXME : non static method in static context
Collection<Contact> coll = DataBaseHandler.getAllContacts();
if(!coll.isEmpty()) {
contactListAdapter.addAll(coll);
}
}
}
As far as I can tell this is all that is involved with this error. If I make getAllContacts() static then I will get the same old error but in a different spot: getWritableDatabase();

Related

[HELP] Filter SimpleAdapter / ListView

Hi, this is actually 2 questions.
I have a list of items stored in one string array and a list of the collections those items are in stored in a second string array.
I want the user to be able to search for an item and see in which collection it exists.
I have managed to do this in a less-than-elegant way by simply combining the 2 string arrays into one and using a ListView with a EditText with a TextWatcher to filter the results. This all works but the result is not so eye-pleasing. I use this to make the distinction between item and collections:
Code:
<item>ITEM \r\n -> COLLECTION(S)
when defining the string array.
As I said, it works but I would like the COLLECTION(S) to be formatted differently from the ITEM. Is this possible in a ListView?
This is my current code:
Code:
public class Search extends Activity {
/** Called when the activity is first created. */
private ListView lv1;
private EditText ed;
private String[] lv_arr;
private ArrayList<String> arr_sort= new ArrayList<String>();
int textlength=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
lv1=(ListView)findViewById(R.id.listView1);
ed=(EditText)findViewById(R.id.editText1);
lv_arr = getResources().getStringArray(R.array.all_cont);
lv1.setAdapter(new ArrayAdapter<String>(this, R.layout.row , lv_arr));
ed.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textlength=ed.getText().length();
arr_sort.clear();
for(int i=0;i<lv_arr.length;i++)
{
if(textlength<=lv_arr[i].length())
{
if(ed.getText().toString().equalsIgnoreCase((String) lv_arr[i].subSequence(0, textlength)))
{
arr_sort.add(lv_arr[i]);
}}}
lv1.setAdapter(new ArrayAdapter<String>(Search.this, R.layout.row , arr_sort));
}
});
}}
As a second solution that looks more elegant, I used a SimpleAdapter to put the 2 original string arrays in the ListView like this:
Code:
public class Search extends ListActivity {
private String[] l1;
private String[] l2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seach);
ArrayList<Map<String, String>> list = buildData();
String[] from = { "name", "packs" };
int[] to = { android.R.id.text1, android.R.id.text2 };
SimpleAdapter adapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, from, to);
setListAdapter(adapter);}
private ArrayList<Map<String, String>> buildData() {
l1 = getResources().getStringArray(R.array.items);
l2 = getResources().getStringArray(R.array.packs);
Integer i;
int to = l1.length;
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
for(i=0;i < to;i++){
list.add(putData(l1[i], l2[i]));
}
return list;
}
private HashMap<String, String> putData(String name, String packs) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", name);
item.put("packs", packs);
return item;
}
}
This looks a lot better but I can't figure out how to make use of the EditText to filter the results.
Any help is welcomed!
Hey!
I read your post and I think it would be better to make a class like this:
Code:
public class ListItem
{
public String itemName;
public String collectionName;
}
And then in your Search activity you can Make a single ArrayList of the type ListItem. Populate this array in a way similar to how you are populating the ArrayList of the HashMaps.
Now for setting the ListAdapter you'll have to make a custom view for each row of the list(this custom row could contain two text views, one for the item name and the other for the collection and you can give them their own formatting), and then subclass the ArrayAdapter class and override its getView method.
Heres a couple of links that might be helpful:
http://www.ezzylearning.com/tutoria...droid-listview-items-with-custom-arrayadapter
http://stackoverflow.com/questions/2265661/how-to-use-arrayadaptermyclass
Hope this helps
The_R said:
Hey!
I read your post and I think it would be better to make a class like this:
Code:
public class ListItem
{
public String itemName;
public String collectionName;
}
And then in your Search activity you can Make a single ArrayList of the type ListItem. Populate this array in a way similar to how you are populating the ArrayList of the HashMaps.
Now for setting the ListAdapter you'll have to make a custom view for each row of the list(this custom row could contain two text views, one for the item name and the other for the collection and you can give them their own formatting), and then subclass the ArrayAdapter class and override its getView method.
Heres a couple of links that might be helpful:
http://www.ezzylearning.com/tutoria...droid-listview-items-with-custom-arrayadapter
http://stackoverflow.com/questions/2265661/how-to-use-arrayadaptermyclass
Hope this helps
Click to expand...
Click to collapse
Thanks once more. I looked over the links and I think I have an idea of how to adapt it to my app. Will try it tomorrow and let you know
Yeah. Let me know if it worked.
The_R said:
Yeah. Let me know if it worked.
Click to expand...
Click to collapse
I feel like my head is exploding.
I did what you said but I still have some issues. Here's what I did:
1. Created a new class, Icons:
Code:
public class Icons {
public String icon;
public String title;
public Icons(){
super();
}
public Icons(String icon, String title) {
super();
this.icon = icon;
this.title = title;
}
}
Created a new XML for the style of the ListView:
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/icon_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:textSize="18sp"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="@+id/in_pack"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textSize="12sp" />
</LinearLayout>
created a new Adapter:
Code:
public class IconsAdapter extends ArrayAdapter<Icons>{
Context context;
int layoutResourceId;
Icons data[] = null;
public IconsAdapter(Context context, int layoutResourceId, Icons[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
IconsHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new IconsHolder();
holder.txtIcon = (TextView)row.findViewById(R.id.icon_name);
holder.txtTitle = (TextView)row.findViewById(R.id.in_pack);
row.setTag(holder);
}
else
{
holder = (IconsHolder)row.getTag();
}
Icons icons = data[position];
holder.txtTitle.setText(icons.title);
holder.txtIcon.setText(icons.icon);
return row;
}
static class IconsHolder
{
TextView txtIcon;
TextView txtTitle;
}
}
Modified my Search class like this:
Code:
public class Search extends Activity {
private ListView listView1;
private String[] l1;
private String[] l2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seach);
l1 = getResources().getStringArray(R.array.items);
l2 = getResources().getStringArray(R.array.packs);
Integer i;
int to = l1.length;
// for(i=0;i < to;i++){}
Icons Icons_data[] = new Icons[]
{
new Icons(l1[0], l2[0]),
new Icons(l1[1], l2[1]),
new Icons(l1[2], l2[2]),
new Icons(l1[3], l2[3]),
};
IconsAdapter adapter = new IconsAdapter(this,
R.layout.row, Icons_data);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
}
}
Up until now, everything works (almost) great. Only thing I can't do is figure out how to assign the items in the Icons_data[] array automatically (my for(...) statement doesn't seem to want to fit anywhere). Format looks good and manually inserting data does what it's supposed to. Still need to figure out the automatic data inserting thing...my arrays have 100-150 elements
What I also can't figure out is how the hell to perform the filtering/search on this new special Array... I tried using the old method with the TextWatcher on an EditText field but can't seem to be able to adapt this part:
Code:
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textlength=ed.getText().length();
[B][U]arr_sort.clear();[/U][/B]
for(int i=0;i<to;i++)
{
if(textlength<=l1[i].length())
{
if(ed.getText().toString().equalsIgnoreCase((String) l1[i].subSequence(0, textlength)))
{
[B][U]arr_sort.add(l1[i]);[/U][/B]
}
}
}
[B][U]lv1.setAdapter(new ArrayAdapter<String>(Search.this, R.layout.row , arr_sort))[/U][/B];
}
});
ed is the EditText item. I guess I would need to make arr_sort of the type Icons[] and then change the Bold, Underlined lines to something...but no idea what... Is it even possible to do it like i'm doing it? Or should I look for another method to sort it?
Hey I modified your search class:
Code:
public class Search extends Activity {
private ListView listView1;
// Note: I've removed the two String[] class members cause we are going
// store this data in a single Icons[] member
private Icons[] iconsData;
private ArrayList<Icons> arr_sort; // Note: Changed the type of arr_sort
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seach);
// We'll create two local String[] variables to assemble the data
String[] l1 = getResources().getStringArray(R.array.items);
String[] l2 = getResources().getStringArray(R.array.packs);
// get the total number of icons
int totalIcons = l1.length;
// Allocate the data for the Icon[] array
iconsData = new Icons[totalIcons];
// Now to populate the Icon array
for (int i = 0; i < totalIcons; i++)
{
iconsData[i] = new Icons(l1[i], l2[i]);
}
// Rest remains the same
IconsAdapter adapter = new IconsAdapter(this,
R.layout.row, iconsData);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
}
}
Now you don't need to change the sorting method. Just slight modifications to fit the data structuring is all that is needed.
Code:
public void onTextChanged(CharSequence s, int start, int before, int count)
{
textlength = ed.getText().length();
arr_sort.clear();
for(int i = 0 ; i < to; i++)
{
if(textlength <= iconsData[i].icon.length()) //Note: l1 becomes iconsData[i].icon
{
if(ed.getText().toString().equalsIgnoreCase((String) iconsData[i].icon.subSequence(0, textlength)))
{
arr_sort.add(iconsData[i]); // Note: we'll store iconsData[i] if a match is found
}
}
}
lv1.setAdapter(new IconsAdapter(Search.this, R.layout.row , arr_sort.toArray()));
}
Haven't tested it. So watch out for some possible errors.
I can't thank you enough but I still need your help.
The first part works (modifications to the Search class).
Now, In the same class, after that part, I add the filtering part:
Code:
ed=(EditText)findViewById(R.id.editText1);
ed.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
int textlength = ed.getText().length();
arr_sort.clear();
for(int i=0;i<[B][I]totalIcons[/I][/B];i++)
{
if(textlength <= iconsData[i].icon.length()) //Note: l1 becomes iconsData[i].icon
{
if(ed.getText().toString().equalsIgnoreCase((String) iconsData[i].icon.subSequence(0, textlength)))
{
arr_sort.add(iconsData[i]); // Note: we'll store iconsData[i] if a match is found
}
}
}
listView1.setAdapter(new IconsAdapter(Search.this, R.layout.row , [U][B](Icons[])[/B][/U] arr_sort.toArray()));
}
});
}
}
I had to make 2 changes in order for it not to give any errors. First, I changed the "to" in the for statement to "totalIcons" since that's actually the number we need and "to" was not defined. When I did this I also had to change "totalIcons" to final int since I had this error:"Cannot refer to a non-final variable totalIcons inside an inner class defined in a different method"
Also, I had to add the (Icons[]) at the end because of this error: "The constructor IconsAdapter(Search, int, Object[]) is undefined". The suggested fixes was changing the constructor for IconsAdapter, adding a new constructor or adding the (Icons[]) thing.
Now I have no errors in Eclipse but when I run the app and try to type something in the EditText box the app crashes...I get these errors:
04-12 19:32:27.032: E/AndroidRuntime(998): FATAL EXCEPTION: main
04-12 19:32:27.032: E/AndroidRuntime(998): java.lang.NullPointerException
04-12 19:32:27.032: E/AndroidRuntime(998): at mmarin.iconpack.manager.Search$1.onTextChanged(Search.java:70)
04-12 19:32:27.032: E/AndroidRuntime(998): at android.widget.TextView.sendOnTextChanged(TextView.java:6295)
04-12 19:32:27.032: E/AndroidRuntime(998): at android.widget.TextView.handleTextChanged(TextView.java:6336)
04-12 19:32:27.032: E/AndroidRuntime(998): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:6485)
04-12 19:32:27.032: E/AndroidRuntime(998): at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889)
Sorry about the previous untested code. I was in a rush to go somewhere but I saw you online and thought that it'd be better if I replied.
Anyways, I think the problem is that "totalIcons" is a local variable. So remove the final keyword. And in the for loop in the TextWatcher's onTextChanged method instead of using totalIcons use the length property of iconsData:
Code:
for (int i = 0; i < iconsData.length; i++)
Should fix the runtime error
First off, please do all the things you have to do and don't waste your time with me. I really really appreciate you trying to help me so if you don't have time for this, it's absolutely no problem.
Now, the runtime errors are still there after the change
04-12 19:59:24.332: E/AndroidRuntime(1034): FATAL EXCEPTION: main
04-12 19:59:24.332: E/AndroidRuntime(1034): java.lang.NullPointerException
04-12 19:59:24.332: E/AndroidRuntime(1034): at mmarin.iconpack.manager.Search$1.onTextChanged(Search.java:70)
04-12 19:59:24.332: E/AndroidRuntime(1034): at android.widget.TextView.sendOnTextChanged(TextView.java:6295)
04-12 19:59:24.332: E/AndroidRuntime(1034): at android.widget.TextView.handleTextChanged(TextView.java:6336)
04-12 19:59:24.332: E/AndroidRuntime(1034): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:6485)
04-12 19:59:24.332: E/AndroidRuntime(1034): at mmarin.iconpack.manager.Search$1.onTextChanged(Sea rch.java:70)
Can you paste line 70 of Search.java?
Wait are you doing this in onCreate?
Code:
arr_sort = new ArrayList<Icons>();
That's what I was looking for (actually how to enable line numbers in Eclipse )
here it is:
Code:
arr_sort.clear();
Yep. We aren't creating arr_sort. So its a null pointer.
Do this somewhere in onCreate
Code:
arr_sort = new ArrayList<Icons>();
ok, that solved that issue. now the problem is with this:
Code:
listView1.setAdapter(new IconsAdapter(Search.this, R.layout.row, (Icons[]) arr_sort.toArray()));
What error/exception do you get?
04-12 20:17:26.663: E/AndroidRuntime(1205): FATAL EXCEPTION: main
04-12 20:17:26.663: E/AndroidRuntime(1205): java.lang.ClassCastException: [Ljava.lang.Object;
04-12 20:17:26.663: E/AndroidRuntime(1205): at mmarin.iconpack.manager.Search$1.onTextChanged(Search.java:84)
I guess that the arr_sort.toArray() creates an Object[] but we need a Icons[] resource for the IconsAdapter.
Am I close?
Yea you are right
One quick and ugly solution I can think of is maybe creating an Icons array right after the search and then filling it with all the items in the arraylist. This happens right before you are setting the adapter
Code:
Icons[] data = new Icons[arr_data.size()];
for (int i = 0; i < arr_data.size(); i++)
{
data[i] = arr_data.get(i);
}
listView1.setAdapter(new IconsAdapter(Search.this, R.layout.row, data));
This should work but it isn't really a good solution =/
Quick and ugly works for me! You're 3 for 3!
You get a big special thanks in my App!!!
Once more, thank you and probably I will ask for your help again in a short while, with another issue I can't figure out.
It will probably be about getting a market link for an app through the Share menu in the Play Store and using that information to send an e-mail - but I will try to figure it out for myself . I already found how to get my app in the "Share" menu in the Play Store and also (possibly) how to save that information to a string. Now i have to find out how to actually get my app to start a certain Activity when it is started by the Play Store app. Will do that over the weekend
Sure! I'll be happy to help out with whatever little bit know!

[HELP] Program a Scrollable tabs

Hello guys,
I need your help to find how to code a Scrollable tabs (ics), I find no help and I'm looking but I can not find!
Had you any idea? Thank you in advance
http://developer.android.com/design/media/tabs_scrolly.mp4
Source: http://developer.android.com/design/patterns/actionbar.html#contextual
youpi01 said:
Hello guys,
I need your help to find how to code a Scrollable tabs (ics), I find no help and I'm looking but I can not find!
Had you any idea? Thank you in advance
http://developer.android.com/design/media/tabs_scrolly.mp4
Source: http://developer.android.com/design/patterns/actionbar.html#contextual
Click to expand...
Click to collapse
Create an actionbar and edit the layout to fit your needs.
Code:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle startInfo) {
super.onCreate(startInfo);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tabCPU = actionBar.newTab()
.setText(R.string.cpu_tab_title)
.setTabListener(new TabListener<CpuInfoActivity>(
this, "artist", CpuInfoActivity.class));
actionBar.addTab(tabCPU);
Tab tabMEM = actionBar.newTab()
.setText(R.string.mem_tab_title)
.setTabListener(new TabListener<MemInfoActivity>(
this, "artist", MemInfoActivity.class));
actionBar.addTab(tabMEM);
}
thank you very much I will test it now!
Well I just tried but I can not, it shows me many errors!
Is there source code available for me to view?
Hello, I have made ​​some progress ...
I would just like to add tabs and be able to edit in xml!
How do I add Java code to the link to my different layout (tabs)
Attached is the file in question!
Code:
package com.youpi.app;
import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class AppActivity extends SherlockActivity implements OnPageChangeListener {
private ViewPager viewPager;
private static int NUM_VIEWS = 2;
private MyPagerAdapter pagerAdapter;
private TextView pageIndicator;
private int currentPage = 0;
private View[] tabViews = new View[NUM_VIEWS];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pagerAdapter = new MyPagerAdapter();
viewPager = (ViewPager) findViewById(R.id.viewpager1);
TextView textView1 = new TextView(this);
textView1.setText("Tunandroid View Pager Example");
textView1.setTextSize(20);
ImageView imageView1 = new ImageView(this);
imageView1.setImageResource(R.drawable.ic_launcher);
[COLOR="Red"]tabViews[0] = textView1;
tabViews[1] = imageView1;
tabViews[2]= here add a new tab but in xml![/COLOR]
viewPager.setAdapter(pagerAdapter);
viewPager.setOnPageChangeListener(this);
viewPager.setCurrentItem(currentPage);
pageIndicator = (TextView)findViewById(R.id.pageIndicator);
pageIndicator.setText(String.valueOf(currentPage+1));
}
private class MyPagerAdapter extends PagerAdapter
{
@Override
public int getCount() {
return NUM_VIEWS;
}
@Override
public Object instantiateItem(View collection, int position) {
((ViewPager) collection).addView(tabViews[position],0);
return tabViews[position];
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View)view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==(object);
}
@Override
public void finishUpdate(View arg0) {}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {}
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int position) {
currentPage = position;
pageIndicator.setText(String.valueOf(currentPage+1));
}
}

[Q] Gallery App from Stock S3 (same as Note 2) to AOSP Roms like CM 10.1

Hello guys first of all I'm new here so i hope i make everything correct and I'm in the right section.
I just searched for the Stock S3 Gallery (the same like Note 2 with Gallery Flow Effect) but I couldn't find somehting that runs on AOSP Roms, so I just googled a little bit and found these Code (Source was stackoverflow.com, sorry but I can't post the links because Forum Rules with 10 Posts).
Code:
gal_caterories.setAdapter(new CategoryPreferenceAdapter (context,
response.customOfferPojo.offerAvailableCategories,1));
public class CategoryPreferenceAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
public static List<String> thumbnailsselection;
private ViewHolder holder = new ViewHolder();
private List<CategoriesClass> categories = new ArrayList<CategoriesClass>();
public static final int ACTIVITY_CREATE = 10;
public static List<Integer> prefferedCategories = new ArrayList<Integer>();
private int i = 0;
// Keep all Images in array
// public Integer[] mThumbIds = { R.drawable.pic_1, R.drawable.pic_2,
// R.drawable.pic_3, R.drawable.pic_4, R.drawable.pic_5,
// R.drawable.pic_6, R.drawable.pic_7, R.drawable.pic_8,
// R.drawable.pic_9, R.drawable.pic_10, R.drawable.pic_11,
// R.drawable.pic_12, R.drawable.pic_13, R.drawable.pic_14,
// R.drawable.pic_15 };
public CategoryPreferenceAdapter(Context c,
List<CategoriesClass> categories, List<Integer> prefferedCategories) {
this.mContext = c;
this.categories = categories;
this.prefferedCategories = prefferedCategories;
mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
thumbnailsselection = new ArrayList<String>();
}
class ViewHolder {
ImageView imageview;
TextView tv_categoryname;
// LinearLayout ll_category_selection;
CheckBox cb_check_category;
}
[user=439709]@override[/user]
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = mInflater
.inflate(R.layout.template_categories_grid, null);
holder.imageview = (ImageView) convertView
.findViewById(R.id.iv_image_category);
holder.tv_categoryname = (TextView) convertView
.findViewById(R.id.tv_categoryname);
// holder.ll_category_selection = (LinearLayout) convertView
// .findViewById(R.id.ll_category_selection);
holder.cb_check_category = (CheckBox) convertView
.findViewById(R.id.cb_check_category);
if (prefferedCategories.contains(categories.get(position).categoryid)) {
holder.cb_check_category.setChecked(true);
} else {
holder.cb_check_category.setChecked(false);
holder.cb_check_category.setBackgroundColor(Color.TRANSPARENT);
}
holder.tv_categoryname.setText(categories.get(position).category
.toUpperCase());
holder.cb_check_category
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
prefferedCategories.add(categories.get(position).categoryid);
} else {
holder.cb_check_category
.setBackgroundColor(Color.TRANSPARENT);
prefferedCategories.remove(categories.get(position).categoryid);
}
}
});
ImageLoader imageload = new ImageLoader(mContext);
imageload.DisplayImage(
categories.get(position).defaultCategoryImage.toString(),
holder.imageview);
holder.imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
return convertView;
}
[user=439709]@override[/user]
public int getCount() {
// TODO Auto-generated method stub
return categories.size();
}
[user=439709]@override[/user]
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
[user=439709]@override[/user]
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
Can someone maybe build an App with this Code? I ask because I have no clue about that, but I think the sourcecode is good and many guys would be happy. Maybe some Guy has the time to do it? (It is maybe a cool App for the Playstore too).
Thank you for the attention.
Lostion said:
Hello guys first of all I'm new here so i hope i make everything correct and I'm in the right section.
I just searched for the Stock S3 Gallery (the same like Note 2 with Gallery Flow Effect) but I couldn't find somehting that runs on AOSP Roms, so I just googled a little bit and found these Code (Source was stackoverflow.com, sorry but I can't post the links because Forum Rules with 10 Posts).
Code:
gal_caterories.setAdapter(new CategoryPreferenceAdapter (context,
response.customOfferPojo.offerAvailableCategories,1));
public class CategoryPreferenceAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
public static List<String> thumbnailsselection;
private ViewHolder holder = new ViewHolder();
private List<CategoriesClass> categories = new ArrayList<CategoriesClass>();
public static final int ACTIVITY_CREATE = 10;
public static List<Integer> prefferedCategories = new ArrayList<Integer>();
private int i = 0;
// Keep all Images in array
// public Integer[] mThumbIds = { R.drawable.pic_1, R.drawable.pic_2,
// R.drawable.pic_3, R.drawable.pic_4, R.drawable.pic_5,
// R.drawable.pic_6, R.drawable.pic_7, R.drawable.pic_8,
// R.drawable.pic_9, R.drawable.pic_10, R.drawable.pic_11,
// R.drawable.pic_12, R.drawable.pic_13, R.drawable.pic_14,
// R.drawable.pic_15 };
public CategoryPreferenceAdapter(Context c,
List<CategoriesClass> categories, List<Integer> prefferedCategories) {
this.mContext = c;
this.categories = categories;
this.prefferedCategories = prefferedCategories;
mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
thumbnailsselection = new ArrayList<String>();
}
class ViewHolder {
ImageView imageview;
TextView tv_categoryname;
// LinearLayout ll_category_selection;
CheckBox cb_check_category;
}
[user=439709]@override[/user]
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = mInflater
.inflate(R.layout.template_categories_grid, null);
holder.imageview = (ImageView) convertView
.findViewById(R.id.iv_image_category);
holder.tv_categoryname = (TextView) convertView
.findViewById(R.id.tv_categoryname);
// holder.ll_category_selection = (LinearLayout) convertView
// .findViewById(R.id.ll_category_selection);
holder.cb_check_category = (CheckBox) convertView
.findViewById(R.id.cb_check_category);
if (prefferedCategories.contains(categories.get(position).categoryid)) {
holder.cb_check_category.setChecked(true);
} else {
holder.cb_check_category.setChecked(false);
holder.cb_check_category.setBackgroundColor(Color.TRANSPARENT);
}
holder.tv_categoryname.setText(categories.get(position).category
.toUpperCase());
holder.cb_check_category
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
prefferedCategories.add(categories.get(position).categoryid);
} else {
holder.cb_check_category
.setBackgroundColor(Color.TRANSPARENT);
prefferedCategories.remove(categories.get(position).categoryid);
}
}
});
ImageLoader imageload = new ImageLoader(mContext);
imageload.DisplayImage(
categories.get(position).defaultCategoryImage.toString(),
holder.imageview);
holder.imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
return convertView;
}
[user=439709]@override[/user]
public int getCount() {
// TODO Auto-generated method stub
return categories.size();
}
[user=439709]@override[/user]
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
[user=439709]@override[/user]
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
Can someone maybe build an App with this Code? I ask because I have no clue about that, but I think the sourcecode is good and many guys would be happy. Maybe some Guy has the time to do it? (It is maybe a cool App for the Playstore too).
Thank you for the attention.
Click to expand...
Click to collapse
Me too .Looking for the same thing for a long time.
But could not find any.:crying:
Just wishing some guy to build an apk that would run on all phones like some other games.
Keep searching and kindly share if you find any.:good:
Thanks
Thank you man for posting this i think a lot of us wish to get this app on cyanogenmod for example i hope there's a hero dev. Can do this for us
Regards
تم الإرسال من جهازي GT-I9300 بواسطة تاباتلك 4 now Free

[SOLVED][Q] Cannot find a symbol, while other symbols are found fine

I couldn't think of a better way to word the title, but the issue I'm having is this: I'm using HoloColorPicker by Lars Werkman. Now I have correctly imported the library, I can see the ColorPicker and other views from the library in my app, the only symbol that is failing to be found is OnColorChangedListener. I looked through the code of the library and it is an interface that is defined in ColorPicker.java, which I am importing, and the ColorPicker view itself, as I already stated, is appearing in my GUI fine.
Here is my associated code:
Code:
import com.larswerkman.holocolorpicker.SaturationBar;
import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.ValueBar;
public class ColorChooserDialog extends DialogFragment {
private String title;
private CustomColor cur_color;
private boolean edit = false;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.choose_color_dialog_title);
// Inflate layout color chooser view and set to builder
LayoutInflater layout_inflater = getActivity().getLayoutInflater();
View view = layout_inflater.inflate(R.layout.color_chooser_view, null);
builder.setView(view);
// Get views by IDs
EditText hex_input = (EditText)view.findViewById(R.id.hexInput);
EditText red_input = (EditText)view.findViewById(R.id.redInput);
EditText green_input = (EditText)view.findViewById(R.id.greenInput);
EditText blue_input = (EditText)view.findViewById(R.id.blueInput);
ColorPicker color_picker = (ColorPicker)view.findViewById(R.id.colorPicker);
SaturationBar sat_bar = (SaturationBar)view.findViewById(R.id.saturationBar);
ValueBar val_bar = (ValueBar)view.findViewById(R.id.valueBar);
// Connect bars to color picker
color_picker.addSaturationBar(sat_bar);
color_picker.addValueBar(val_bar);
// When color is changed via picker, set text fields
color_picker.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});
// Add listener for when HEX value is changed
hex_input.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {}
@Override
public void beforeTextChanged(CharSequence chars, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence chars, int start, int before, int count) {
//TODO
}
});
builder.setPositiveButton(
R.string.ok_button,
new DialogInterface.OnClickListener() {
// User clicked OK, add color to palette
public void onClick(DialogInterface dialog, int id) {
//TODO
}
}
);
builder.setNegativeButton(
R.string.cancel_button,
new DialogInterface.OnClickListener() {
// User cancelled the dialog, don't create palette
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}
);
// Create the AlertDialog object and return it
return builder.create();
}
}
OK, so I figured it out, I didn't notice this at first because Java is not my first language, but the OnColorChangedListener is within the ColorPicker class, so I instead of using this:
Code:
color_picker.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});
I needed to use this:
Code:
color_picker.setOnColorChangedListener(new [B]ColorPicker.[/B]OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});

[Q] referencing a dynamica fragment

Hi
Frag1 which is a side navigation drawer, is instantiated in MainActivity.java onCreate by manager.findFragmentById since there is a fragment tag in a xml file.
Frag2 and Frag3 are dynamically committed at some point by a manager, non of their layouts contain a <fragment> tag, they are not committed in the MainActivity onCreate method and thus don't have ids or tags either.
When a button on frag2 is pressed, frag3 "a dialogFragment" needs to be displayed on the screen for user login inputs.
How can I get this to work? I am getting null pointer when referencing frag2 in MainActivity.
here is a illustrative stripped down version of the code. sorry for any unintended typos
Thank you for helping
Frag2.java
Code:
public class Frag2 extends Fragment {
Frag2Communicator = mFrag2communicator;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.frag2_layout, container, false);
class ClickHandler implements View.OnClickListener {
@Override
public void onClick(View v) {
mFrag2communicator.show_frag3();
}
}
}
public interface Frag2Communicator {
public void show_frag3();
}
public void setFrag2Communicator(Frag2Communicator frag2communicator) {
mFrag2communicator = frag2communicator;
}
}
MainActivity.java
Code:
public class MainActivity extends ActionBarActivity implements frag2.frag2Communicator {
protected void onCreate(Bundle savedInstanceState) {
Frag2 frag2 = getSupportFragmentManager().findFragmentById(R.id.frag_2);
//frag_2 is the id of a RelativeLayout inside a ScrollView inside frag2_layout.xml
//I tried to move this ide to the root tag "ScrollView" but still get a null pointer.
frag2.setFrag2Communicator(this);
public void show_frag3(){
FragmentManager manager = getSupportFragmentManager();
Frag3 frag_3 = new Frag3();
frag_3.show(manager, "loging");
}
}
}

Categories

Resources