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