In EditWorkDetails.java (extend to fragment), it has two different layout, which are footer and footer layout .
Error
Error:(60, 47) error: cannot find symbol method getLayoutInflater()
EditWorkDetails.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View edit_details = inflater.inflate(R.layout.edit_work_details, container, false);
dbHelper = new MyDatabaseHelper(getActivity());
sqlcon = new WorkDetailsAPI(getContext());
listViewUpdate = (ListView) edit_details.findViewById(R.id.listViewEdit);
addClaims=(Button) edit_details.findViewById(R.id.buttonClaims);
footer = (AbsoluteLayout) edit_details.getLayoutInflater().inflate(R.layout.total_hours, null);
totalHours = (TextView) footer.findViewById(R.id.textView10);
footerLayout = (FrameLayout) edit_details.getLayoutInflater().inflate(R.layout.under_list_view_button, null);
btnSubmit = (Button) footerLayout.findViewById(R.id.btnSave);
btnAddClaims = (Button) footerLayout.findViewById(R.id.addClaims);
objMyCustomBaseAdapter = new MyCustomBaseAdapter(getActivity(), results, listViewUpdate, footerLayout, footer);
Bundle bundle = this.getArguments();
if(getArguments()!=null)
{
ID=bundle.getLong("ID");
}
Toast.makeText(getActivity(),ID+"",Toast.LENGTH_LONG).show();
BuildEditDetails(ID);
totalHours.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="175dp"
android:layout_height="33dp"
android:textColor="#color/indian_red"
android:textStyle="bold"
android:textSize="18sp"
android:id="#+id/textView10"
android:layout_x="174dp"
android:layout_y="16dp" />
</AbsoluteLayout>
under_list_view_button.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="181dp"
android:layout_height="wrap_content"
android:id="#+id/addClaims"
android:layout_marginLeft="15px"
android:drawableRight="#mipmap/claims"
android:text="Add Claims"/>
<Button
android:layout_width="130dp"
android:layout_height="wrap_content"
android:id="#+id/btnSave"
android:drawableRight="#mipmap/submit"
android:layout_marginLeft="450px"
android:text="Submit" />
</FrameLayout>
How do I fix this ? Thanks
try to do
footerLayout = (FrameLayout) getActivity().getLayoutInflater().inflate(R.layout.under_list_view_button, null);
Related
I am using fragments. I have an textview in fragment and I want to get value in main activity.
This is my fragment layout
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="30dp"
android:layout_marginEnd="50dp"
android:layout_marginStart="55dp"
android:layout_marginTop="10dp"
android:columnCount="20"
android:orientation="horizontal"
android:rowCount="16"
tools:context="com.lipi.worldofelements.MainFragment">
<Space
android:layout_width="25dp"
android:layout_height="35dp"
android:layout_column="2"
android:layout_row="2"
android:background="#color/colorButtonNobelGasses" />
<LinearLayout
android:layout_width="505dp"
android:layout_height="165dp"
android:layout_column="4"
android:layout_columnSpan="13"
android:layout_margin="5dp"
android:layout_row="2"
android:layout_rowSpan="5"
android:orientation="horizontal"
>
<RelativeLayout
android:id="#+id/btnElement"
android:layout_width="165dp"
android:layout_height="match_parent"
android:background="#color/colorButtonNonmetals"
android:clickable="true"
>
<TextView
android:id="#+id/txtElemSym"
style="#style/AppTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="25dp"
android:clickable="true"
android:gravity="center"
android:linksClickable="true"
android:onClick="btnClikcedToast"
android:text="#string/H"
android:textColor="#ffff"
android:textSize="#dimen/buttonXL"
/>
I am loading fragment with this function inside my MainActivity.java:
//Set the fragment activity
MainFragment fragment = new MainFragment();
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
This my fragment class
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
databaseHelper = new ElementDatabaseAdapter(getActivity());
txtElemSym = (TextView) rootView.findViewById(R.id.txtElemSym);
return rootView;
When I click the textview(txtElemSym) main activity runs "btnClikcedToast" function inside my MainActivity .
public void btnClikcedToast(View view) {
txtSymbol = (TextView) findViewById(R.id.txtElemSym);
String ElemSymbol = (String) txtSymbol.getText();
Bundle b;
Intent i = new Intent(this, SingleElementData.class);
b = ActivityOptions.makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()).toBundle();
i.putExtra("symbol", ElemSymbol);
startActivity(i, b);
}
I want to get textvalue in this function. I got an error "NullPointerException" after I run this.
How can I do this?
In fragment A, it has listView. When the list is clicked, it should pass the data to fragment B.
A.java
B fragment2 = new B();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment1, fragment2);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
B.java
public class B extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.b, container, false);
Log.d("TAG","fragment2");
return view;
}
}
a.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/some_text"
android:textSize="20sp" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</FrameLayout>
b.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="false">
<AbsoluteLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="218dp"
android:layout_height="47dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Update Page"
android:id="#+id/textView114"
android:layout_x="12dp"
android:layout_y="20dp" />
</AbsoluteLayout>
</ScrollView>
This is how my Fragment A looked like.
When the list is clicked.
What's wrong here :?
in your a.xml use the following :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="#string/app_name"
android:textSize="20sp" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</FrameLayout>
I think may be your problem in instantiating the EditText fields, you'd better declare your items after the view is created, so you have to override the method onViewCreated and make your declarations in it, then put your database work in a try-catch block to make sure it isn't the reason of any problems:
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
name3 = (EditText) view.findViewById(R.id.editText9);
date3 = (EditText) view.findViewById(R.id.editText12);
Bundle bundle = this.getArguments();
date = bundle.getString("date1");
ID = bundle.getString("ID");
RetrievePage(date, ID);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.b, container, false);
return view;
}
public void RetrievePage(String date, String id) {
final String date2 = date;
final String id2 = id;
Log.d("m", id2);
name3.setText("Lim ");
date3.setText(date2);
try {
database = dbHelper.getWritableDatabase();
c = database
.rawQuery(
"SELECT i.Weather FROM Information i LEFT JOIN WorkForce w ON w.TInfo_id = i._id WHERE i.Name = ? AND i._id= ? ",
new String[] { String.valueOf("Lim"),
String.valueOf(id2) }, null);
if (c != null) {
while (c.moveToNext()) {
Info I = new Info();
Force WF = new Force();
String Weather = c.getString(c
.getColumnIndexOrThrow(MyDatabaseHelper.Weather));
}
}
c.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
About fragments overlapping, you must declare each fragment as a separated fragment, and the main FragmentActivity is the activity that holds the fragments which in your case must be an empty activity with only the ViewPager or FrameLayout that contain fragments:
<RelativeLayout 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:background="#drawable/bg" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ac_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9" />
</RelativeLayout>
So, you must have MainActivity that contains two fragments FragmentA and FragmentB
for reference look at this answer.
i am a beginer android-developer and i need some help:
There is a Fragment in my Project - TasksFragment, there is a ListView element on it. On ListView, using ArrayAdapter Items are formed by a custom layout for Item and then added to ListView. The problem is, that ListView don't react on click processing events.
Here are the code fragments:
TaskAdapter class...
public class TaskAdapter extends ArrayAdapter<Task> {
public TaskAdapter(ArrayList<Task> tasks) {
super(getActivity(), 0, tasks);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_task, null);
}
Task task = getItem(position);
TextView titleTextView = (TextView) convertView.findViewById(R.id.task_list_item_titleTextView);
titleTextView.setText(task.getTitle());
CheckBox solvedCheckBox = (CheckBox) convertView.findViewById(R.id.task_list_item_solvedCheckBox);
solvedCheckBox.setChecked(task.isSolved());
return convertView;
}
}
ItemClick fragment.
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tasks_fragment, null);
mTasks = TaskLab.get(getActivity()).getTasks();
final ListView lvMain = (ListView) view.findViewById(R.id.listViewTasks);
lvMain.setClickable(true);
TaskAdapter adapter = new TaskAdapter(mTasks);
setHasOptionsMenu(true);
lvMain.setAdapter(adapter);
lvMain.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Task task = (Task)lvMain.getItemAtPosition(position);
Toast.makeText(getActivity().getApplicationContext(), task.getTitle() + " was clicked", Toast.LENGTH_LONG).show();
Intent i = new Intent(getActivity(), AddTaskActivity.class);
startActivity(i);
}
});
return view;
}
XML Layout for List_Item_Task
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="#+id/task_list_item_solvedCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentRight="true"
android:enabled="false"
android:padding="4dp"/>
<TextView
android:id="#+id/task_list_item_titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/task_list_item_solvedCheckBox"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textSize="22dp"/>
</RelativeLayout>
Xml layout for tasks_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3f638b">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textViewTasksFragmentHeader"
android:text="Задачи"
android:textSize="30dp"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listViewTasks" />
</LinearLayout>
Yes your listview is not clickable.
Just add this in your checkbox layout
android:focusable="false"
Your items xml should look like this
<?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" >
<CheckBox
android:id="#+id/task_list_item_solvedCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" //Add this
android:layout_alignParentRight="true"
android:gravity="center"
android:padding="4dp" />
<TextView
android:id="#+id/task_list_item_titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/task_list_item_solvedCheckBox"
android:paddingBottom="5dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="5dp"
android:textSize="22dp"
android:textStyle="bold" />
Now it should work. I have tested it :)
I want to programmatically add a view to ScrollView that is apart of a Fragment layout.
I have attempeted the following code:
public class MessageDetail extends Fragment {
View layout;
TextView messageText;
Conversation conversation;
List<Message> messages;
LayoutInflater inflater;
ViewGroup container;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
this.inflater = inflater;
this.container = container;
layout = inflater.inflate(R.layout.messenger_detail, container,
false);
messageText = (TextView) layout.findViewById(R.id.tvMessage);
return layout;
}
public void loadConversation(Conversation conversation) {
messageText.setText(conversation.getSubject());
LinearLayout messagesView = (LinearLayout)layout.findViewById(R.id.llMessageDetail);
LinearLayout messageBody = new LinearLayout(getActivity());
View body = inflater.inflate(R.layout.messagebody, container);
messagesView.addView(body);
}
}
messagebody.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llMessageBody"
android:layout_width="fill_parent"
android:layout_margin="5dp"
android:layout_height="200dp"
android:background="#353535"
android:orientation="vertical" >
<TextView
android:id="#+id/tvMSBodyFrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Research Station:"
android:textColor="#FFFFAA"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tomatohigh"
/>
</LinearLayout>
message_detail.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:background="#d3d6da"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FFAA00" >
<TextView
android:id="#+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Select a Message:"
android:textColor="#353535"
android:textSize="30dp" />
</LinearLayout>
<ScrollView
android:id="#+id/svMessageDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#9900AA"
android:minHeight="300dp" >
<LinearLayout
android:id="#+id/llMessageDetail"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content" >
</LinearLayout>
</ScrollView>
</LinearLayout>
The final implementaion would see me loop through a list of messages and add the a view with the message_body layout and change each part of the layout to the correct values of each message
Any ideas how to achieve this?
You can do like this:
YourView varView = new YourView(this);
myButton.setLayoutParams(new YourLayout.LayoutParams());
yourParentLayout.addView(varView);
Example: Add a button in parent linear layout
Button myButton = new Button(this);
myButton.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
myLayout.addView(myButton);
i have created a listView in my Fragment and my own adapter to create my own layout for the listView but its not showing anything
the xml for my listView layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill|right" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/textView_listViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView_adressList1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bronze_pin_level" />
<ImageView
android:id="#+id/imageView_adressList2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bronze_pin_level" />
<ImageView
android:id="#+id/imageView_adressList3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bronze_pin_level" />
</LinearLayout>
</LinearLayout>
the xml for my listView
<?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" >
<ListView
android:id="#+id/listView_adressList"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.25" >
</ListView>
<ImageView
android:id="#+id/imageView_adressList1"
android:layout_width="match_parent"
android:layout_height="43dp"
android:src="#drawable/bottom_me" />
the fragment code:
public class FragList extends Fragment {
ListView listView;
View myFragmentView;
List<String> adressList;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.frag_list, container, false);
listView = (ListView) myFragmentView
.findViewById(R.id.listView_adressList);
adressList = new ArrayList<String>();
adressList.add("Marvin");
adressList.add("Markus");
adressList.add("Bob");
ArrayAdapter<String> adapter = new MyAdapter(getActivity(),
R.layout.adress_list_layout, adressList);
listView.setAdapter(adapter);
return myFragmentView;
}
public class MyAdapter extends ArrayAdapter<String>{
private List<String> values;
ImageView btn1, btn2, btn3;
Context cont;
int layoutID;
public MyAdapter(Context context, int resource, List<String> values) {
super(context, resource);
this.values = values;
this.cont = context;
this.layoutID = resource;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.cont
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(this.layoutID,
parent, false);
TextView tv1 = (TextView) rowView
.findViewById(R.id.textView_listViewText);
tv1.setText(values.get(position));
btn1 = (ImageView) rowView
.findViewById(R.id.imageView_adressList1);
btn2 = (ImageView) rowView
.findViewById(R.id.imageView_adressList2);
btn3 = (ImageView) rowView
.findViewById(R.id.imageView_adressList3);
return rowView;
}
}
}
The Problem is that the listView is not shown on the screen. It´s just a white screen.
Apparently I am doing something quite wrong, but I cant figure out what.
try with
view = View.inflate(cont, R.layout.name_of_your_listView_layout , null);
and not
View rowView = inflater.inflate(this.layoutID,
parent, false);
change the value for height and try again......