作业

public class MainActivity extends Activity {
Gallery gr;
GalleryAdapter galleryAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);

galleryAdapter = new GalleryAdapter(MainActivity.this);
       gallery.setAdapter(galleryAdapter);
       //相应的点击事件
       gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int i, long id) {
Toast.makeText(MainActivity.this, "您点击的是" + i, Toast.LENGTH_LONG).show();

}
       });
   }
}


package com.example.popowindo;


import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;


public class MainActivity extends Activity {
PopupWindow pw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void la(View v){
View view = View.inflate(getApplicationContext(), R.layout.popo, null);
GridView gr = (GridView) view.findViewById(R.id.gridView1);
gr.setAdapter(new MyAdapter());
pw = new PopupWindow(view,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
pw.showAsDropDown(v);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setFocusable(true);
//指定按钮在下方出现1
//gsrent v 是按钮 v.getparent()式布局
pw.showAtLocation((View) v.getParent(),Gravity.BOTTOM, 0, 0);

}
class MyAdapter extends BaseAdapter{
private int[] imagrs = new int[]{
R.drawable.b3,R.drawable.b4,R.drawable.b5,R.drawable.b6
};
private String[] name = new String[]{
"1","2","3","4"
};
@Override
public int getCount() {
// TODO Auto-generated method stub
return name.length;
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return name[position];
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {

if(convertView == null){
convertView = View.inflate(getApplicationContext(), R.layout.time, null);

}
ImageView im = (ImageView) convertView.findViewById(R.id.imageView1);
TextView tx = (TextView) convertView.findViewById(R.id.textView1);
im.setImageResource(position);
tx.setText(name[position]);

return convertView;
}

}
}
package com.example.slidingdouwe;


import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SlidingDrawer;


public class MainActivity extends Activity {
private GridView gridView;  
    private SlidingDrawer slidingDrawer;  
    private ImageView imageView;  
    private int[] icons={  
        R.drawable.widget01, R.drawable.widget02,  
        R.drawable.widget03, R.drawable.widget04,  
        R.drawable.widget05, R.drawable.widget06  
          
    };  
      
    private String[] items={  
        "Phone", "Message", "AddImage", "Music", "Telephone", "SMS"   
    };  
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView)findViewById(R.id.mycontent);  
        slidingDrawer = (SlidingDrawer)findViewById(R.id.sliding_drawer);  
        imageView = (ImageView)findViewById(R.id.my_image);  
        MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons);  
        gridView.setAdapter(adapter);  
        slidingDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {  
              
            public void onDrawerOpened() {  
                imageView.setImageResource(R.drawable.right1);  
            }  
        });  
        slidingDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {  
              
            public void onDrawerClosed() {  
                imageView.setImageResource(R.drawable.left1);  
            }  
        });  
    }  
}
public class MainActivity extends Activity {
Spinner s1;
AutoCompleteTextView tx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1= (Spinner) findViewById(R.id.spinner1); 
ArrayAdapter<String> st = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_item);
st.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
st.add("dad");
st.add("da");
st.add("dd");
st.add("ad");
s1.setAdapter(st);
tx= (AutoCompleteTextView) findViewById(R.id.sp);
String[] name ={"1","2","2","3","4","5","6","11","23","23","33","44","35","66"};
ArrayAdapter<String> sm = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_dropdown_item_1line,name);
tx.setAdapter(sm);

}
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页