androidannotations 的简单使用

package com.example.androidannotations_jar;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@EActivity(R.layout.activity_main)
public class TestActivity extends Activity{


	@ViewById(R.id.textview)
	TextView tv;
	@ViewById(R.id.button1)
	Button btn;
	
	@ViewById(R.id.editText1)
	EditText et;
	/**
	 * 加载view 之后进行的处理
	 */
    @AfterViews
    void afterView(){
    	Log.i("zhouke", "afterView..."+Thread.currentThread().getName());
    	btn.setText("afterview");
    	tv.setText("第一个activity 界面");
    }
    @Click(R.id.button1)
    void processClick(){
    	tv.setText("点击了");
    	new Thread(){
    		public void run() {
    			showToastDelay();
    		};
    	}.start();
    
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	Log.i("zhouke", "onCreate...1");
    	super.onCreate(savedInstanceState);
    	Log.i("zhouke", "onCreate...2");
    }
    /**
     * 利用ui 线程显示一个toast
     */
    @UiThread
    void showToast(){
    	Toast.makeText(this , "toast.."+Thread.currentThread().getName(), 0).show();
    }
    /**
     * 延迟显示
     */
    @UiThread(delay=1000)
    void showToastDelay(){
    	Toast.makeText(this , "toast.222."+Thread.currentThread().getName(), 0).show();
    }

}



需要注意的是清单文件的配置

<activity
            android:name="com.example.androidannotations_jar.TestActivity_"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

androidannotations-api-3.0.1.jar 只需要把这个buildpath 即可,否则报错,重复引用资源的错误。。

package tk.woppo.sunday.widget;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById;

import com.example.tianqi.R;

import tk.woppo.sunday.model.SimpleWeatherModel;
import tk.woppo.sunday.util.WeatherUtil;

/**
 * Created by Ho on 2014/7/3.
 */

@EViewGroup(R.layout.layout_simple_item)
public class SimpleWeatherItem extends LinearLayout {
    @ViewById(R.id.ll_simple_item)
    LinearLayout ll;

    @ViewById(R.id.tv_simple_item_weather)
    TextView tvWeather;

    @ViewById(R.id.tv_simple_item_temp)
    TextView tvTemp;

    @ViewById(R.id.tv_simple_item_week)
    TextView tvWeek;

    @ViewById(R.id.iv_simple_item_Weather)
    ImageView ivWeather;

    public SimpleWeatherItem(Context context) {
        super(context);
    }

    public void bind(SimpleWeatherModel model, int position) {
        if (position == 0) {
            ll.setBackgroundResource(R.drawable.simple_item_first);
        } else {
            ll.setBackgroundResource(R.drawable.simple_item);
        }
        tvWeather.setText(model.getWeather());
        tvTemp.setText(model.getTemp());
        tvWeek.setText(model.getWeek());
        ivWeather.setImageResource(WeatherUtil.getIcon(model.getWeather()));
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值