1 / 7

User Interface Layout Interaction

User Interface Layout Interaction. Interacting with a user. Events. Event Handlers/Listeners. The root of GUI elements is the View class. UI elements such as Buttons Labels Editable text Images Etc derive from the View class.

alyn
Download Presentation

User Interface Layout Interaction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. User Interface • Layout • Interaction

  2. Interacting with a user. Events Event Handlers/Listeners

  3. The root of GUI elements is the Viewclass. UI elements such as • Buttons • Labels • Editable text • Images • Etc • derive from the View class. • We define our app’s response to a click by implementing an instance of View.OnClickListenerinterface. Handling Clicks • public class View{ • … • //nested class • public interface OnClickListener { • void onClick(View v); • } • … • }

  4. Click Handler idioms: 1. Have the class that owns the GUI element implement the OnClickListenerinterface. 2. Create an anonymous class that implements OnClickListenerinterface. 3. Create an anonymous class that implements OnClickListenerinterface.

  5. 1. Have the class that owns the GUI element implement the OnClickListenerinterface. • public class PixFragment extends Fragment implements View.OnClickListener{ • @Override • public View onCreateView(LayoutInflaterinflater, ViewGroupcontainer,BundlesavedInstanceState) { • View v = inflater.inflate(R.layout.pix_frag_layout, container, false); • ImageViewmSplashView = (ImageView)v.findViewById(R.id.pix_view); • mSplashView.setOnClickListener(this); • return v; • } • public void onClick(View v){ • // handle the click • Log.d("PixFragment", "I was clicked"); • } • }

  6. 2 Create an anonymous class that implements OnClickListenerinterface. • public class PixFragment extends Fragment{ • private View.OnClickListenermSplashViewListener = new View.OnClickListener() { • @Override • public void onClick(View v) { • // handle the click • Log.d("PixFragment", "I was clicked"); • } • }; • @Override • public View onCreateView(LayoutInflaterinflater, ViewGroupcontainer,BundlesavedInstanceState) { • View v = inflater.inflate(R.layout.pix_frag_layout, container, false); • ImageViewmSplashView = (ImageView)v.findViewById(R.id.pix_view); • mSplashView.setOnClickListener(mSplashViewListener); • return v; • } • }

  7. 3 Create an anonymous class that implements OnClickListenerinterface. • public class PixFragment extends Fragment implements View.OnClickListener{ • @Override • public View onCreateView(LayoutInflaterinflater, ViewGroupcontainer,BundlesavedInstanceState) { • View v = inflater.inflate(R.layout.pix_frag_layout, container, false); • ImageViewmSplashView = (ImageView)v.findViewById(R.id.pix_view); • mSplashView.setOnClickListener(new View.OnClickListener(){ • public void onClick(View v){ • // handle the click • Log.d("PixFragment", "I was clicked"); • } • }); • return v; • } • }

More Related