查找图片
来源:互联网 发布:西安广电网络电视台 编辑:程序博客网 时间:2024/06/18 13:46
结果效果图
代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ImageView android:id="@+id/ivImage" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" /> <EditText android:id="@+id/etImageUrl" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="请输入图片的地址" /> <Button android:id="@+id/btnView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/button_bg" android:onClick="viewImage" android:text="浏览" /></LinearLayout>
public class Dictionary extends Activity implements OnClickListener,TextWatcher {private DBHelper dbHelper; // 用户输入文本框private AutoCompleteTextView word; // 定义数据库的名字private SQLiteDatabase database;private Button searchWord; // 搜索按钮private TextView showResult; // 用户显示查询结果@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);dbHelper = new DBHelper(getBaseContext());// 打开数据库database = dbHelper.openDatabase();init();searchWord.setOnClickListener(this); // 绑定监听器word.addTextChangedListener(this); // 绑定文字改变监听器}public void init() {searchWord = (Button) findViewById(R.id.btnSearch);word = (AutoCompleteTextView) findViewById(R.id.etWord);showResult = (TextView) findViewById(R.id.tvSearchResult);}public void afterTextChanged(Editable s) {Cursor cursor = database.rawQuery("select english as _id from t_words where english like ?",new String[] { s.toString() + "%" });// 新建新的AdapterDictionaryAdapter dictionaryAdapter = new DictionaryAdapter(this,cursor, true);// 绑定适配器word.setAdapter(dictionaryAdapter);}public void beforeTextChanged(CharSequence s, int start, int count,int after) {}public void onTextChanged(CharSequence s, int start, int before, int count) {}public void onClick(View view) {// 查询指定的单词String sql = "select chinese from t_words where english=?";Cursor cursor = database.rawQuery(sql, new String[] { word.getText().toString() });String result = "查无该词"; // 如果查找单词,显示其中文的意思if (cursor.getCount() > 0) { cursor.moveToFirst(); // 须使用moveToFirst方法将记录指针移动到第1条记录的位置result = cursor.getString(cursor.getColumnIndex("chinese")).replace("&", "&");}showResult.setText(word.getText() + "\n" + result.toString());// 将结果显示到TextView中}
输入网址即可得到图片
public class Dictionary extends Activity implements OnClickListener,TextWatcher {private DBHelper dbHelper; // 用户输入文本框private AutoCompleteTextView word; // 定义数据库的名字private SQLiteDatabase database;private Button searchWord; // 搜索按钮private TextView showResult; // 用户显示查询结果@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);dbHelper = new DBHelper(getBaseContext());// 打开数据库database = dbHelper.openDatabase();init();searchWord.setOnClickListener(this); // 绑定监听器word.addTextChangedListener(this); // 绑定文字改变监听器}public void init() {searchWord = (Button) findViewById(R.id.btnSearch);word = (AutoCompleteTextView) findViewById(R.id.etWord);showResult = (TextView) findViewById(R.id.tvSearchResult);}public void afterTextChanged(Editable s) {Cursor cursor = database.rawQuery("select english as _id from t_words where english like ?",new String[] { s.toString() + "%" });// 新建新的AdapterDictionaryAdapter dictionaryAdapter = new DictionaryAdapter(this,cursor, true);// 绑定适配器word.setAdapter(dictionaryAdapter);}public void beforeTextChanged(CharSequence s, int start, int count,int after) {}public void onTextChanged(CharSequence s, int start, int before, int count) {}public void onClick(View view) {// 查询指定的单词String sql = "select chinese from t_words where english=?";Cursor cursor = database.rawQuery(sql, new String[] { word.getText().toString() });String result = "查无该词"; // 如果查找单词,显示其中文的意思if (cursor.getCount() > 0) { cursor.moveToFirst(); // 须使用moveToFirst方法将记录指针移动到第1条记录的位置result = cursor.getString(cursor.getColumnIndex("chinese")).replace("&", "&");}showResult.setText(word.getText() + "\n" + result.toString());// 将结果显示到TextView中}
0 0
- 查找图片
- 查找类似图片&关键字查找图片
- word查找替换图片
- 项目无用图片查找
- jquery正则图片查找
- 查找透明图片
- Java图片上查找图片算法
- Java图片上查找图片算法
- Java图片上查找图片算法
- Picasa2图片查找浏览工具
- 批量查找和拷贝图片
- 查找相同图片的网站
- dwz 图片查找带回处理
- 重复图片的删除/查找
- 编程操作Word 查找 替换 图片
- 总结一个技巧 通过图片查找资料
- 通过字符串构建查找图片资源ID
- 通过字符串构建查找图片资源ID
- 唯有坚持方能成功
- MPI安装问题
- Selector select方法阻塞register的解决方法
- 使用FreeSWITCH SIP落地的配置总结
- 【 C语言】将一个数字按字符形式逐个输出,例如1234,输出为1 2 3 4
- 查找图片
- iOS tableview cell 中自定义lable
- Win8.1的Matlab7卸载问题
- Java大文本文件切割
- LeetCode172_FactorialTrailingZeroes java题解
- leetcode 43 : Multiply Strings
- mysql练手专用项目
- textview和网页显示一样
- C++字符串之间转化——多字节字符集