Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 941

KetaiList

$
0
0

Hi. I copied the KetaiList class into a new processing tab to be able to customize it. But I only managed to change the backGround color. I tried to set textColor and do some padding, but although it doesn't give any errors, it also hasn't any effect. Any idea what is wrong? Thanks in advance

import java.lang.reflect.Method;
import java.util.ArrayList; 
import processing.core.PApplet;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView; 

// void onKetaiListSelection(String selection) - selection is the string * selected from the list

public class KetaiList extends ListView { 

  private PApplet parent; 
  private ArrayAdapter<String> adapter; 
  String name = "KetaiList"; 
  String selection = "";
  ListView self; 
  RelativeLayout layout; 
  private Method parentCallback; 
  String title = "";
  public KetaiList(PApplet _parent, ArrayList<String> data) {       
    super(_parent.getActivity().getApplicationContext());       
    parent = _parent;       
    adapter = new ArrayAdapter<String>(parent.getActivity(), android.R.layout.simple_list_item_1, data);        
    init();
  } 
  public KetaiList(PApplet _parent, String[] data) {        
    super(_parent.getActivity().getApplicationContext());       
    parent = _parent;       
    adapter = new ArrayAdapter<String>(parent.getActivity(), android.R.layout.simple_list_item_1, data);        
    init();
  }
  public KetaiList(PApplet _parent, String _title, String[] data) {     
    super(_parent.getActivity().getApplicationContext());       
    parent = _parent;       
    title = _title;     
    adapter = new ArrayAdapter<String>(parent.getActivity(), android.R.layout.simple_list_item_1, data);        
    init();
  } 
  public KetaiList(PApplet _parent, String _title, ArrayList<String> data) {        
    super(_parent.getActivity().getApplicationContext());       
    parent = _parent;       
    title = _title;     
    adapter = new ArrayAdapter<String>(parent.getActivity(), android.R.layout.simple_list_item_1, data);        
    init();
  } 
  public void refresh() {       
    if (adapter == null)            return;     
    parent.getActivity().runOnUiThread(new Runnable() {         
      public void run() {               
        adapter.notifyDataSetChanged();
      }
    }
    );
  } 
  public String getSelection() {        
    return selection;
  }
  private void init() {     
    setBackgroundColor(Color.BLUE);     
  //  setTextColor(Color.BLACK);
    setAlpha(1);        
    self = this;        
    layout = new RelativeLayout(parent.getActivity());      

    if (title != "") {          
      TextView tv = new TextView(parent.getActivity());
   //   tv.setPadding(100,100,0,0);
      tv.setText(title);            
   //   tv.setTextColor(Color.parseColor("#bdbdbd"));
      setHeaderDividersEnabled(true);           
      addHeaderView(tv);
    }       
    try {           
      parentCallback = parent.getClass().getMethod("onKetaiListSelection", new Class[] { KetaiList.class });            
      PApplet.println("Found onKetaiListSelection...");
    } 
    catch (NoSuchMethodException e) {
    }       
    setAdapter(adapter);        
    setOnItemClickListener(new OnItemClickListener() {          
      public void onItemClick(AdapterView<?> p, View view, int position, long id) {                 
        selection = adapter.getItem(position).toString();               
        layout.removeAllViewsInLayout();                
        try {                   
          parentCallback.invoke(parent, new Object[] { self });
        } 
        catch (Exception ex) {
        }               
        self.setVisibility(View.GONE);              
        ((ViewManager) self.getParent()).removeView(self);              
        parent.getActivity().runOnUiThread(new Runnable() {                 
          public void run() {                       
            layout.removeAllViews();                        
            layout.setVisibility(View.GONE);
          }
        }
        );
      }
    }
    ); 
    parent.getActivity().runOnUiThread(new Runnable() {         
      @SuppressWarnings("deprecation")      
        public void run() {             
        parent.getActivity().addContentView(self, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
      }
    }
    );
  }
}

Viewing all articles
Browse latest Browse all 941

Trending Articles