[SOLVED][Q] Cannot find a symbol, while other symbols are found fine - Android Q&A, Help & Troubleshooting

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
}
});

Related

Using multiple drawables with MapsForge

After following the developer tutorial using Google Maps, my code is crashing when trying to execute the map code from the start up screen. I am trying to add Big East basketball team icons on the map in the correct GPS location. When that part of the code is taken out it works but I can't find what I'm doing wrong. Thanks for any help you can provide.
Here is the map code:
Code:
public class MapsForgeViewer extends MapActivity implements LocationListener, OnClickListener {
private static final double latitudePitt = 40.443061;
private static final double longitudePitt = -79.962273;
private static final double latitudeUConn = 41.807975;
private static final double longitudeUConn = -72.253626;
private MapView mapView;
private GeoPoint myCurrentLocation;
private Button findPosition;
private Button roster;
private Button schedule;
private Button stats;
private Button exit;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.map_view);
// setting up the location listener
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
100, 0, mlocListener);
// end of location listener setup
// find from XML and set onClickListeners
findPosition = (Button) findViewById(R.id.findPositionButton);
roster = (Button) findViewById(R.id.roster);
schedule = (Button) findViewById(R.id.schedule);
stats = (Button) findViewById(R.id.stats);
exit = (Button) findViewById(R.id.exit);
findPosition.setOnClickListener(this);
roster.setOnClickListener(this);
schedule.setOnClickListener(this);
stats.setOnClickListener(this);
exit.setOnClickListener(this);
// end of mapView layout setup
// setting the up the map at the proper zoom level and creating the
// scale bars and buttons
mapView = (MapView) findViewById(R.id.mapView);
mapView.setMapViewMode(MapViewMode.MAPNIK_TILE_DOWNLOAD);
mapView.setBuiltInZoomControls(true);
mapView.setScaleBar(true);
mapView.setClickable(true);
findPositionButton(myCurrentLocation);
mapView.getController().setZoom(14);
setCenterlocation();
// end of mapView setup
//Put pins on map
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawablePitt = this.getResources().getDrawable(R.drawable.pittspin);
CustomItemizedOverlay itemizedOverlayPitt = new CustomItemizedOverlay(drawablePitt, this);
Drawable drawableUConn = this.getResources().getDrawable(R.drawable.connpin);
CustomItemizedOverlay itemizedOverlayUConn = new CustomItemizedOverlay(drawableUConn, this);
//Create points using latitude and longitude
GeoPoint pointPitt = new GeoPoint(latitudePitt, longitudePitt);
OverlayItem overlayitemPitt = new OverlayItem(pointPitt, "Pitt", "Panthers");
GeoPoint pointUConn = new GeoPoint(latitudeUConn, longitudeUConn);
OverlayItem overlayitemUConn = new OverlayItem(pointUConn, "UConn", "Huskies");
itemizedOverlayPitt.addOverlay(overlayitemPitt);
itemizedOverlayUConn.addOverlay(overlayitemUConn);
//add to map
mapOverlays.add(itemizedOverlayPitt);
mapOverlays.add(itemizedOverlayUConn);
}
public void onClick(View v)
{
switch (v.getId())
{
case (R.id.findPositionButton):
findPositionButton(myCurrentLocation);
break;
case (R.id.roster):
// get data from database
break;
case (R.id.schedule):
break;
case (R.id.stats):
break;
// close the app
case (R.id.exit):
finish();
break;
}
}
public void findPositionButton(GeoPoint p)
{
mapView.getController().setCenter(p);
}
@Override
// resumes the actions of the application on a pause
protected void onResume()
{
super.onResume();
}
// sets the center of the screen on the map
protected void setCenterlocation()
{
if (myCurrentLocation == null)
mapView.getController().setCenter(new GeoPoint(39.00, -100.00));
else
mapView.getController().setCenter(myCurrentLocation);
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude());
if (gp != null)
myCurrentLocation = gp;
}
// activates when the current provider is disabled, or inactive
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(), "GPS Disabled",
Toast.LENGTH_LONG).show();
}
// activates when a provider is found.
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(), "GPS Enabled",
Toast.LENGTH_LONG).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
public void onLocationChanged(Location arg0)
{
}
public void onProviderDisabled(String provider)
{
}
public void onProviderEnabled(String provider)
{
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
CustomItemizedOverlay:
Code:
public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
public ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
public MapsForgeViewer mActivtyl;
public CustomItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}

[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

[Q] How do I filter a retrieve data in Spinner?

I'm new to android,stuck in this part of my code.
I do hope, someone would help me with it.
As ,I've stuck for quite a while and have to complete within 2 days,
If I would like to filter in spinner based on the dates, how should I do it? For example,
I've a list of events, and in my spinner
when I select "Today", it will show out the list for today.
I've tried out the coding, however, I met some error. The part in BOLD, ** is having error.
I would like to get the XML data from here:
[attached in this thread]
the highlighted part
here is my coding: AndroidXMLParsingActivity.java
public class AndroidXMLParsingActivity extends ListActivity implements OnItemSelectedListener {
String[] browseby;
String[] dates = { "Today", "Tomorrow", "Next Week",
};
ArrayList<String> browse = new ArrayList<String>();
ArrayList<String> mPostingData = new ArrayList<String>();
Spinner s1;
ListView listview;
CustomAdapter cus;
// All static variables
static final String URL = " URL ";
// XML node keys
static final String KEY_EVENT = "event"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_START_TIME = "start_time";
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_EVENT);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_START_TIME, parser.getValue(e, KEY_START_TIME));
// adding HashList to ArrayList
menuItems.add(map);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_item, new String[] { KEY_TITLE,KEY_START_TIME }, new int[] {
R.id.title,
R.id.startTime });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title))
.getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
startActivity(in);
}
});
listview = (ListView) findViewById(R.id.listView1);
s1 = (Spinner) findViewById(R.id.spinner1);
for (int i = 0; i < browseby.length; i++) {
browse.add(browseby);
}
// aa = new
// ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Category);
s1.setOnItemSelectedListener(this);
mPostingData = browse;
for (int i = 0; i < mPostingData.size(); i++) {
if (mPostingData.size() > 0)
Log.i("Datas", mPostingData.get(i));
}
cus = new CustomAdapter(this, 0);
setListAdapter(cus);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, dates);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(aa);
}
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
// listview.setFilterText(Category[position]);
String Text = s1.getSelectedItem().toString();
cus.getFilter().filter(Text);
cus.notifyDataSetChanged();
}
public void onNothingSelected(AdapterView<?> parent) {
// listview.setFilterText("");
}
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, "You have selected " + mPostingData.get(position),
Toast.LENGTH_SHORT).show();
}
class CustomAdapter extends ArrayAdapter<String> {
public void setData(ArrayList<String> mPpst) {
mPostingData = mPpst;// contains class items data.
}
@override
******public Filter getFilter() {
return new Filter() {
@override
protected void publishResults(CharSequence constraint,
FilterResults start_time) {
if (start_time.equals("2013-09-25") {
setData((ArrayList<String>) start_time.values);
} else {
setData(browse);// set original values
}
notifyDataSetInvalidated();
}******
@override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
if (!TextUtils.isEmpty(constraint)) {
constraint = constraint.toString();
ArrayList<String> foundItems = new ArrayList<String>();
if (browse != null) {
for (int i = 0; i < browse.size(); i++) {
if (browse.get(i).contains(constraint)) {
System.out.println("My datas" + browse.get(i));
foundItems.add(browse.get(i));
} else {
}
}
}
result.count = foundItems.size();// search results found
// return count
result.values = foundItems;// return values
} else {
result.count = -1;// no search results found
}
return result;
}
};
}
LayoutInflater mInflater;
public CustomAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
// TODO Auto-generated constructor stub
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@override
public int getCount() {
// TODO Auto-generated method stub
return mPostingData.size();
}
@override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = mInflater.inflate(R.layout.row, null);
vh.t1 = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(vh);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
vh = (ViewHolder) convertView.getTag();
}
if (mPostingData.size() > 0)
vh.t1.setText(mPostingData.get(position));
return convertView;
}
}
static class ViewHolder {
TextView t1;
}
}
randomise said:
I'm new to android,stuck in this part of my code.
I do hope, someone would help me with it.
As ,I've stuck for quite a while and have to complete within 2 days,
If I would like to filter in spinner based on the dates, how should I do it? For example,
I've a list of events, and in my spinner
when I select "Today", it will show out the list for today.
I've tried out the coding, however, I met some error. The part in BOLD, ** is having error.
I would like to get the XML data from here:
[attached in this thread]
the highlighted part
here is my coding: AndroidXMLParsingActivity.java
public class AndroidXMLParsingActivity extends ListActivity implements OnItemSelectedListener {
String[] browseby;
String[] dates = { "Today", "Tomorrow", "Next Week",
};
ArrayList<String> browse = new ArrayList<String>();
ArrayList<String> mPostingData = new ArrayList<String>();
Spinner s1;
ListView listview;
CustomAdapter cus;
// All static variables
static final String URL = " URL ";
// XML node keys
static final String KEY_EVENT = "event"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_START_TIME = "start_time";
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_EVENT);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_START_TIME, parser.getValue(e, KEY_START_TIME));
// adding HashList to ArrayList
menuItems.add(map);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_item, new String[] { KEY_TITLE,KEY_START_TIME }, new int[] {
R.id.title,
R.id.startTime });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title))
.getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
startActivity(in);
}
});
listview = (ListView) findViewById(R.id.listView1);
s1 = (Spinner) findViewById(R.id.spinner1);
for (int i = 0; i < browseby.length; i++) {
browse.add(browseby);
}
// aa = new
// ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Category);
s1.setOnItemSelectedListener(this);
mPostingData = browse;
for (int i = 0; i < mPostingData.size(); i++) {
if (mPostingData.size() > 0)
Log.i("Datas", mPostingData.get(i));
}
cus = new CustomAdapter(this, 0);
setListAdapter(cus);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, dates);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(aa);
}
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
// listview.setFilterText(Category[position]);
String Text = s1.getSelectedItem().toString();
cus.getFilter().filter(Text);
cus.notifyDataSetChanged();
}
public void onNothingSelected(AdapterView<?> parent) {
// listview.setFilterText("");
}
public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, "You have selected " + mPostingData.get(position),
Toast.LENGTH_SHORT).show();
}
class CustomAdapter extends ArrayAdapter<String> {
public void setData(ArrayList<String> mPpst) {
mPostingData = mPpst;// contains class items data.
}
@override
******public Filter getFilter() {
return new Filter() {
@override
protected void publishResults(CharSequence constraint,
FilterResults start_time) {
if (start_time.equals("2013-09-25") {
setData((ArrayList<String>) start_time.values);
} else {
setData(browse);// set original values
}
notifyDataSetInvalidated();
}******
@override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
if (!TextUtils.isEmpty(constraint)) {
constraint = constraint.toString();
ArrayList<String> foundItems = new ArrayList<String>();
if (browse != null) {
for (int i = 0; i < browse.size(); i++) {
if (browse.get(i).contains(constraint)) {
System.out.println("My datas" + browse.get(i));
foundItems.add(browse.get(i));
} else {
}
}
}
result.count = foundItems.size();// search results found
// return count
result.values = foundItems;// return values
} else {
result.count = -1;// no search results found
}
return result;
}
};
}
LayoutInflater mInflater;
public CustomAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
// TODO Auto-generated constructor stub
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@override
public int getCount() {
// TODO Auto-generated method stub
return mPostingData.size();
}
@override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = mInflater.inflate(R.layout.row, null);
vh.t1 = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(vh);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
vh = (ViewHolder) convertView.getTag();
}
if (mPostingData.size() > 0)
vh.t1.setText(mPostingData.get(position));
return convertView;
}
}
static class ViewHolder {
TextView t1;
}
}
Click to expand...
Click to collapse
Can someone please help me out?
your help will be appreciated.
Thanks

[Q] How to get the position of an item when dropped in a Gridview

Hi there!
I'm trying to know how to get the position of an item when it is already been dropped. I have used a gridview to list images.
my xml code is:
Code:
<RelativeLayout xmlns:android="..."
xmlns:tools="..."
android:id="@+id/parent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:horizontalSpacing="10dip"
android:numColumns="4"
android:verticalSpacing="10dip" />
</RelativeLayout>
here is my mainactivity class:
Code:
public class MainActivity extends Activity implements OnDragListener,
OnItemLongClickListener {
ArrayList drawables;
GridView gridView;
private BaseAdapter adapter;
private int draggedIndex = -1;
private int droppedIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawables = new ArrayList();
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
drawables.add(R.drawable.ic_launcher);
gridView = (GridView) findViewById(R.id.grid_view);
gridView.setOnItemLongClickListener(MainActivity.this);
gridView.setAdapter(adapter = new BaseAdapter() {
@Override
// Get a View that displays the data at the specified position in
// the data set.
public View getView(int position, View convertView,
ViewGroup gridView) {
// try to reuse the views.
ImageView view = (ImageView) convertView;
// if convert view is null then create a new instance else reuse
// it
if (view == null) {
view = new ImageView(MainActivity.this);
}
view.setImageResource((Integer) drawables.get(position));
view.setTag(String.valueOf(position));
return view;
}
@Override
// Get the row id associated with the specified position in the
// list.
public long getItemId(int position) {
return position;
}
@Override
// Get the data item associated with the specified position in the
// data set.
public Object getItem(int position) {
return drawables.get(position);
}
@Override
// How many items are in the data set represented by this Adapter.
public int getCount() {
return drawables.size();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onDrag(View view, DragEvent dragEvent) {
switch (dragEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// Ignore this event
return true;
case DragEvent.ACTION_DRAG_ENTERED:
// Ignore this event
return true;
case DragEvent.ACTION_DRAG_EXITED:
// Ignore this event
return true;
case DragEvent.ACTION_DRAG_LOCATION:
// Ignore this event
return true;
case DragEvent.ACTION_DROP:
// Dropped inside a new view
// get the position where the item is been dropped
adapter.notifyDataSetChanged();
case DragEvent.ACTION_DRAG_ENDED:
view.setOnDragListener(null);
return true;
}
return false;
}
@Override
public boolean onItemLongClick(AdapterView gridView, View view,
int position, long row) {
ClipData.Item item = new ClipData.Item((String) view.getTag());
ClipData clipData = new ClipData((CharSequence) view.getTag(),
new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }, item);
view.startDrag(clipData, new View.DragShadowBuilder(view), null, 0);
view.setVisibility(View.INVISIBLE);
draggedIndex = position;
return true;
}
}
I guessed that i can get the position when the action is "DragEvent.ACTION_DROP" but i cannot come up with the way to get the position!
Any ideas?
thanks in advance

[Q] One TextWatcher for many EditTexts

Hi
I need to change text color of some EditTexts based on character count as they are typed.
in the onActivityCreated of my Fragment class, there are EditTexts etOne and etTwo, which I am able to fetch them using getActivity().findViewById.
I also have
Code:
etOne.addTextChangedListener(myTextWatcher);
etTwo..addTextChangedListener(myTextWatcher);
private final TextWatcher myTextWatcher = 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) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() > 6) {
etOne.setTextColor(getResources().getColor(R.color.warning));
} else {
etOne.setTextColor(getResources().getColor(R.color.primary_text));
}
}
};
Can I check to see which EditText is being "watched" so that I can handle them accordingly?
i.e, Is there a way of knowing which EditText this TextWatcher is attached to inside of myTextWatcher? maybe by using the Editable s variable or somthing?
Thank you

Categories

Resources