Android ID not found, when it is there - java

Android Studio is giving me errors in the Main Activity Java over unresolved symbols or id's. As far as I can see the id's refrenced in the java code exist.
In another app which used these same principles, it worked, I cross refrenced the two apps and could not find anything that stood out.
Here is my java code:
package com.example.android.quizapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;
public class QuizMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_main);
}
public void display(int value) {
TextView quantityTextView = findViewById(R.id.value_text);
quantityTextView.setText(value);
}
public void slider(View view){
SeekBar seekBar = (SeekBar)findViewById(R.id.i);
int Value = seekBar.getProgress();
EditText text = (EditText)findViewById(R.id.valueText);
String name = text.getText().toString();
text.setText(Value);
}
}
Here is my XML: (The id's are there)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.quizapplication.QuizMainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Quiz"
android:textAlignment="center"/>
<TextView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="What is you favorite color?"
android:textAlignment="center"
android:paddingTop="20dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="#+id/title"
/>
<TextView
android:id="#+id/value_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textAlignment="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="300dp"/>
<SeekBar
android:id="#+id/i"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:onClick="slider"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>

Try adding this:
import com.example.android.quizapplication.R;

Related

The button is not visible which is going to connect another activity in android studio

my friends and I are creating an android app for our project and we are new to this and if you think the code is repeated then please post the link.
We have referred from following YouTube video- https://youtu.be/wbsWVtCdiW4
For now we are creating a basic structure for our app. The following is the code entered activity_main.xml which is for button which should connect to other activity but after running the code on emulator and in my phone the app shows a blank screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="157dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="119dp"
android:layout_marginLeft="119dp"
android:layout_marginTop="251dp"
android:layout_marginEnd="97dp"
android:layout_marginRight="97dp"
android:layout_marginBottom="323dp"
android:background="#android:color/holo_blue_light"
android:onClick="startdbapp"
android:text="start db app"
android:textColor="#F8000000"
android:visibility="visible"
tools:visibility="visible" />
</RelativeLayout>
this is the MainActivity.java
package com.login.sqlitedemoapp;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startdbapp(View view) {
new DbManager(this);
startActivity(new Intent(this, InsertData.class));
}
}
this is my 2nd activity file named activity_insert_data.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".InsertData">
<EditText
android:id="#+id/t1"
android:layout_width="242dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="94dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="99dp"
android:layout_marginEnd="75dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="587dp"
android:ems="10"
android:hint="Enter_Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/t2"
android:layout_width="242dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="89dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="194dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
android:layout_marginBottom="492dp"
android:ems="10"
android:hint="Enter_Email"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/t3"
android:layout_width="241dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="88dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="290dp"
android:layout_marginEnd="82dp"
android:layout_marginRight="82dp"
android:layout_marginBottom="396dp"
android:ems="10"
android:hint="Enter_Course"
android:inputType="textPersonName" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="68dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="76dp"
android:layout_marginLeft="76dp"
android:layout_marginTop="395dp"
android:layout_marginEnd="62dp"
android:layout_marginRight="62dp"
android:layout_marginBottom="268dp"
android:onClick="addRecord"
android:text="Insert Record" />
</RelativeLayout>
This it the Main activity named InsertData.java
package com.login.sqlitedemoapp;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class InsertData extends AppCompatActivity
{
EditText t1,t2,t3;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insert_data);
t1=(EditText)findViewById(R.id.t1);
t2=(EditText)findViewById(R.id.t2);
t3=(EditText)findViewById(R.id.t3);
}
public void addRecord(View view)
{
DbManager db = new DbManager(this);
String res = db.addRecord(t1.getText().toString(), t2.getText().toString(),
t3.getText().toString());
Toast.makeText(this, res, Toast.LENGTH_LONG).show();
t1.setText("");
t2.setText("");
t3.setText("");
}
}
I would recommend you to use a constraint layout. Relative layout is old and most of the developers avoid them. Also, check the constraints of the button.

How to make a layout from going up on soft keyboard display?

Every time i try to type in the edittext everything goes up and the header disappears. How do i make a linearlayaout linear1 stay put when i try to type in the edittext. i also tried adding "android:windowSoftInputMode="adjustPan">" to the manifest and it is still not working.
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:background="#5D4037"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher"
android:isScrollContainer="false"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="51dp"
android:text="TextView"
android:textColor="#f0f0f0"
android:textSize="24sp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView1"
android:layout_toEndOf="#+id/imageView1"
android:layout_marginStart="51dp" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:background="#f0f0f0"
android:layout_weight="80"
android:layout_below="#+id/linear1">
</ListView>
<LinearLayout
android:id="#+id/relativeLayout1"
android:weightSum="4"
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#f0f0f0" >
<EditText
android:id="#+id/mess"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:maxHeight="300dp"
android:clickable="true"
android:layout_weight="3"
android:background="#ffffff"
android:focusableInTouchMode="true"
android:scrollbarSize="40dp" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_send"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
This is me java class
import com.obi.thinker.logins.R;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Chatting extends ListActivity {
EditText mess;
ImageButton send;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.yon);
mess = (EditText) findViewById(R.id.mess);
mess.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
}
}
});
}
}
I don't want the soft keyboard to push the header . it should push only the list view up.

Scrollview is not scrolling in AbsoluteLayout

I'm trying to make an Activity which allows the user to press a button and when he presses it, it generates an EditText and a spinner. The problem is that the scroll view does not scroll. The page stays as is.
XML:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_order_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
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="com.example.nir.nestleapp.OrderItemsActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_y="58dp"
android:inputType="phone"
android:ems="10"
android:id="#+id/Quantity"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:hint="quantity"
android:layout_x="11dp" />
<Spinner
android:layout_width="174dp"
android:layout_height="48dp"
android:layout_x="148dp"
android:layout_y="58dp"
android:id="#+id/ItemSpinner" />
</AbsoluteLayout>
</ScrollView>
<Button
android:text="add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="133dp"
android:layout_y="431dp"
android:id="#+id/Generate" />
</AbsoluteLayout>
Java:
package com.example.nir.nestleapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
public class OrderItemsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_items);
final AbsoluteLayout layout = (AbsoluteLayout) findViewById(R.id.activity_order_items);
final Spinner Items=(Spinner)findViewById(R.id.ItemSpinner);
final Button Generate=(Button)findViewById(R.id.Generate);
final EditText Quantity=(EditText)findViewById(R.id.Quantity);
final float[] yPlacement = {280};
Generate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Spinner GeneratedSpinner=new Spinner(OrderItemsActivity.this);
EditText GeneratedQuantity=new EditText(OrderItemsActivity.this);
layout.addView(GeneratedSpinner);
GeneratedSpinner.setX(Items.getX());
yPlacement[0] =yPlacement[0]+200;
GeneratedSpinner.setY(yPlacement[0]);
layout.addView(GeneratedQuantity);
GeneratedQuantity.setX(Quantity.getX());
GeneratedQuantity.setY(yPlacement[0]);
GeneratedQuantity.setHint("quantity");
GeneratedQuantity.setWidth(300);
}
});
}
You can change your Absolute layout, use as child LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_y="58dp"
android:inputType="phone"
android:ems="10"
android:id="#+id/Quantity"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:hint="quantity"
android:layout_x="11dp" />
<Spinner
android:layout_width="174dp"
android:layout_height="48dp"
android:layout_x="148dp"
android:layout_y="58dp"
android:id="#+id/ItemSpinner" />
</LinearLayout>
</ScrollView>
Changing AbsoluteLayout into a LinearLayout is the best way to get rid from this issue.

How to open fragments containing webViews in another activity on button click from fragments of another activity?

I have image-buttons in one of the fragments of an activity and want to open corresponding fragments containing webViews on button clicks in another activity.
I am a beginner so please do give appropriate codes for this.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.administrator.hiha.MainActivity"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="#+id/toolbar"
layout="#layout/tool_bar">
</include>
<fragment
android:id="#+id/upperFragment"
android:layout_width="match_parent"
android:layout_height="200dp"
android:name="com.example.administrator.hiha.Upper_main_Fragment"
android:layout_below="#id/toolbar"
>
</fragment>
<fragment
android:layout_below="#id/upperFragment"
android:id="#+id/lowerFragment"
android:layout_width="match_parent"
android:layout_height="140dp"
android:name="com.example.administrator.hiha.Lower_main_Fragment"
>
</fragment>
<fragment
android:layout_below="#id/lowerFragment"
android:id="#+id/Bottom_Most_Fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.example.administrator.hiha.BottomMostFragment"
tools:layout="#layout/fragment_bottom_most">
</fragment>
<View
android:id="#+id/hLastRow"
android:layout_centerHorizontal="true"
android:layout_below="#id/Bottom_Most_Fragment"
android:layout_width="300dp"
android:layout_height="2dp"
android:background="#EEEEEE"
/>
<TextView
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/hLastRow"
android:layout_centerHorizontal="true"
android:text="Designed \u0026 Developed by me © 2016."/>
</RelativeLayout>
</ScrollView>
MainActivity.java
package com.example.administrator.hiha;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
//Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//toolbar=(Toolbar)findViewById(R.id.toolbar);
}
}
fragment_lower_main.xml
<FrameLayout 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"
tools:context="com.example.administrator.hiha.Lower_main_Fragment">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/about_board"
android:id="#+id/about_img_btn"
android:onClick="onAboutBoardClick"
/>
<TextView
android:id="#+id/text_about_img_btn"
android:text="About Board"
android:layout_below="#id/about_img_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
/>
<ImageButton
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/sarasvati"
android:id="#+id/sarasvati_img_btn"
android:layout_toRightOf="#id/about_img_btn"
android:onClick="onSarasvatiClick"
/>
<TextView
android:layout_toRightOf="#id/text_about_img_btn"
android:id="#+id/text_sarasvati_img_btn"
android:text="Sarasvati"
android:layout_below="#id/sarasvati_img_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
/>
<ImageButton
android:layout_toRightOf="#id/sarasvati_img_btn"
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/scientific_evidences"
android:id="#+id/scientific_evidences_img_btn"
android:onClick="onScientificEvidencesClick"
/>
<TextView
android:layout_toRightOf="#id/text_sarasvati_img_btn"
android:id="#+id/text_scientific_evidences_img_btn"
android:text="Scientific EVidences"
android:layout_below="#id/scientific_evidences_img_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
/>
<ImageButton
android:layout_toRightOf="#id/digital_library_img_btn"
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/affltd_organization"
android:id="#+id/affltd_oragnization_img_btn"
android:onClick="onAffltdOrganizationClick"
/>
<TextView
android:layout_toRightOf="#id/text_digital_library_img_btn"
android:id="#+id/text_affltd_oragnization_img_btn"
android:text="Affiliated Organizations"
android:layout_below="#id/affltd_oragnization_img_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
/>
<ImageButton
android:layout_toRightOf="#id/affltd_oragnization_img_btn"
android:layout_width="100dp"
android:layout_height="80dp"
android:src="#drawable/tender"
android:id="#+id/tender_img_btn"
android:onClick="onTenderClick"
/>
<TextView
android:layout_toRightOf="#id/text_affltd_oragnization_img_btn"
android:id="#+id/text_tender_img_btn"
android:text="Tenders"
android:layout_below="#id/tender_img_btn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
/>
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
Lower_Main_Fragment.java
package com.example.administrator.hiha;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
public class Lower_main_Fragment extends Fragment {
ImageButton about_img_btn;
ImageButton sarasvati_img_btn;
ImageButton scientific_evidences_img_btn;
ImageButton digital_library_img_btn;
ImageButton affltd_oragnization_img_btn;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView=inflater.inflate(R.layout.fragment_lower_main_,container,false);
//cast image buttons
about_img_btn=(ImageButton)getView().findViewById(R.id.about_img_btn);
sarasvati_img_btn=(ImageButton)getView().findViewById(R.id.sarasvati_img_btn);
scientific_evidences_img_btn=(ImageButton)getView().findViewById(R.id.scientific_evidences_img_btn);
digital_library_img_btn=(ImageButton)getView().findViewById(R.id.digital_library_img_btn);
affltd_oragnization_img_btn=(ImageButton)getView().findViewById(R.id.affltd_oragnization_img_btn);
return rootView;
}
//onclick methods of image buttons
public void onAboutBoardClick(View view){
}
}
These are the files in which i want that if i click on about_img_btn then it should open a fragment containing a webView in another activity. The same should be repeated for all the buttons.
Please define the further code that i have to use and mention the files where i have to use it. Thanks!
try this:
in your fragment_lower_main xml:
Give an id to the Framelayout:
<?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"
tools:context="com.example.administrator.hiha.Lower_main_Fragment">
<FrameLayout
android:id="+#id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<--Rest of the code -->
/>
</LinearLayout>
Now in code open new Fragment during button click using:
about_img_btn=(ImageButton)rootView.findViewById(R.id.about_img_btn);
about_img_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AboutUS fragment = new AboutUS();
Replace_fragment(fragment); //pass the fragment u want to replace
}
});
public void ReplaceFragment(Fragment r_fragment) {
FragmentManager fragmentManager = getActivity.getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.fragment_container, r_fragment).commit();
}

Android Studio: Error: <identifier> expected error

I'm a rookie to programming. I've been trying to build an app and been getting these errors as seen in the screenshot. I've tried the "Invalid Caches/Restart" but it didn't help. What am I doing wrong here?
EDIT: Sorry for earlier ignorance. I've added the code snippets.
Login.Java:
package com.example.ankit.mrestro;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends AppCompatActivity implements View.OnClickListener {
Button blogin;
EditText etUsername, etPassword;
TextView RegisterHere,Skip;
UserLocalStorage userLocalStorage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etUsername = (EditText) findViewById(R.id.etUserName);
etPassword = (EditText) findViewById(R.id.etPassword);
RegisterHere = (TextView) findViewById(R.id.RegisterHere);
Skip = (TextView) findViewById(R.id.Skip);
blogin = (Button) findViewById(R.id.blogin);
blogin.setOnClickListener(this);
RegisterHere.setOnClickListener(this);
Skip.setOnClickListener(this);
userLocalStorage= new UserLocalStorage(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.blogin:
User user= new User(null, null);
userLocalStorage.storeUserData(user);
userLocalStorage.SetUserLoggedIn(true);
break;
case R.id.RegisterHere:
startActivity(new Intent(this,Register.class));
break;
case R.id.Skip:
startActivity(new Intent(this,MainActivity.class));
break;
}
}
}
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#drawable/screen1"
android:orientation="vertical"
tools:ignore="HardcodedText" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:orientation="vertical">
<EditText
android:layout_width="350dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:background="#drawable/text"
android:textColor="#A9A9A9A9"
android:textStyle="normal"
android:textSize="20sp"
android:textAlignment="center"
android:text="Username"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<EditText
android:layout_width="350dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:background="#drawable/text"
android:textColor="#A9A9A9A9"
android:textStyle="normal"
android:textSize="20sp"
android:textAlignment="center"
android:text="Password"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:orientation="vertical">
<Button
android:layout_width="#android:dimen/thumbnail_width"
android:layout_height="#android:dimen/app_icon_size"
android:layout_gravity="center"
android:background="#drawable/button"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="20dp"
android:text="Login"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<Button
android:layout_width="120dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:background="#null"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="15dp"
android:text="Register"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:orientation="vertical">
<Button
android:layout_width="120dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:background="#null"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="15dp"
android:text="Skip"/>
</LinearLayout>
</LinearLayout>
Thanks for help guys!
Look at your activity_login.xml to ensure that the ID's you are trying to reference are linked to your UI elements in the layout file. It seems like you are trying to link the class level variable to itself in the findViewById() instead of linking the variable to the ID's in the layout file of the corresponding UI elements.
EDIT:
None of your UI elements (EditText fields, Buttons, or even LinearLayouts) have ID's associated with them. You can either double click the elements when viewing activity_login.xml in the 'Desgin' view to set an ID for the specific element. Otherwise, you can define an ID for the element in the 'Properties' window or explicitly write out android:id="#+id/yourIDHere" in the 'Text' view of the layout file. Whatever you decide to make your ID, you then must call that in name in findViewById() like so: findViewById(R.id.yourIDHere);.
Hope this helps!

Categories