hello fellow programmers!
i doing tutorial have ran snag cannot solve. when set link of xml elements java this:
image1 = (imageview) findviewbyid(r.id.ivimage1); it not recognize id though exact 1 in xml. ivimage1 ivimage2, , ivimage3 don't work rest of elements in class do. doing wrong?
here activity code:
package com.frostbytedev.addsub; import java.io.ioexception; import android.app.activity; import android.content.intent; import android.graphics.bitmap; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imagebutton; import android.widget.imageview; public class photo extends activity implements onclicklistener { bitmap bmp; imagebutton ib; button b; imageview iv, image1, image2, image3, image4; intent i; final static int cameradata = 0; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.photo); initialize(); } private void initialize() { // todo auto-generated method stub iv = (imageview) findviewbyid(r.id.ivreturnedpic); b = (button) findviewbyid(r.id.bsetwall); ib = (imagebutton) findviewbyid(r.id.ibtakepic); image1 = (imageview) findbyid(r.id.ivimage1); image2 = (imageview) findbyid(r.id.ivimage2); image3 = (imageview) findbyid(r.id.ivimage3); image4 = (imageview) findbyid(r.id.ivimage4); b.setonclicklistener(this); ib.setonclicklistener(this); } @override public void onclick(view v) { // todo auto-generated method stub switch(v.getid()){ case r.id.bsetwall: try { getapplicationcontext().setwallpaper(bmp); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } break; case r.id.ibtakepic: i= new intent(android.provider.mediastore.action_image_capture); startactivityforresult(i, cameradata); break; }//closes switch }//closes onclick @override protected void onactivityresult(int requestcode, int resultcode, intent data) { // todo auto-generated method stub super.onactivityresult(requestcode, resultcode, data); if(resultcode == result_ok){ bundle extras = data.getextras(); bmp = (bitmap) extras.get("data"); iv.setimagebitmap(bmp); } }//closes class photo.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <imageview android:id="@+id/ivreturnedpic" android:layout_width="fill_parent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <linearlayout android:layout_width="fill_parent" android:layout_height="60dp" android:orientation="horizontal" android:weightsum="100"> <imagebutton android:id="@+id/ibtakepic" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="78" android:background="@drawable/camera" /> <button android:id="@+id/bsetwall" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="22" android:text="set wallpaper" /> </linearlayout> <horizontalscrollview android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <imageview android:id="@+id/ivimage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <imageview android:id="@+id/ivimage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <imageview android:id="@+id/ivimage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </linearlayout> </horizontalscrollview> </linearlayout> thanks help!
try cleaning project project -> clean , build again.
Comments
Post a Comment