Skip to content

Instantly share code, notes, and snippets.

@csdear
Created March 5, 2014 20:13
Show Gist options
  • Select an option

  • Save csdear/877aef58ddca7c600a4f to your computer and use it in GitHub Desktop.

Select an option

Save csdear/877aef58ddca7c600a4f to your computer and use it in GitHub Desktop.
Inflate Inflates a view or layout in the onCreate method or getView()
//Required Import
import android.view.LayoutInflater;
//Inflating a view within the onCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO - Ex., Inflate footerView for footer_view.xml file
TextView <<tvInstanceName>> = (TextView) getLayoutInflater().inflate(R.layout.<<viewXMLlayout>>, null);
getListView().addFooterView(footerView);
}
// Creating a view to display an ITEM. Inflating a layout in the getView()
public View getView(int position, View convertView, ViewGroup parent) {
//Getting the current item.
final ToDoItem toDoItem = (ToDoItem) getItem(position);
//Inflating a view for the ITEM.
RelativeLayout itemLayout = (RelativeLayout) LayoutInflater.from(
mContext).inflate(R.layout.todo_item, null);
// final TextView titleView = null;
final TextView titleView = (TextView) itemLayout
.findViewById(R.id.titleView);
titleView.setText(toDoItem.getTitle());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment