activity

java – View search Result in a new Activity (Android Firebase)


I have a search form on a fragment which works perfectly. At the moment i have a recyclerView at the bottom of the form but I want it to load the search result on a new activity. Please Help

XML Code:

<LinearLayout 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"
    android:layout_marginTop="55dp"
    android:orientation="vertical"
    tools:context="com.ranake.rana.Search">

    <!-- TODO: Update blank fragment layout -->

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayout">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:orientation="vertical">


                <EditText
                    android:id="@+id/search_field"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:background="@drawable/input_outline2"
                    android:drawableLeft="@drawable/ic_make"
                    android:drawablePadding="10dp"
                    android:gravity="center_vertical"
                    android:hint="Make"
                    android:inputType="textPersonName"
                    android:padding="10dp"
                    android:textColorHint="#7f8c8d"
                    android:textSize="14sp" />

            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="7dp"
                android:orientation="vertical">


                <EditText
                    android:id="@+id/className"
                    android:layout_width="match_parent"
                    android:layout_height="45dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:background="@drawable/input_outline2"
                    android:drawableLeft="@drawable/ic_model"
                    android:drawablePadding="10dp"
                    android:gravity="center_vertical"
                    android:hint="Model"
                    android:inputType="text"
                    android:padding="10dp"
                    android:textColorHint="#7f8c8d"
                    android:textSize="14sp" />

            </LinearLayout>



            <LinearLayout
                android:id="@+id/linearLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="42dp"
                    android:layout_marginBottom="10dp"
                    android:layout_marginEnd="10dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginStart="20dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/button_red_border"
                    android:text="Clear"
                    android:textColor="@color/colorPrimary" />

                <Button
                    android:id="@+id/search_btn"
                    android:layout_width="wrap_content"
                    android:layout_height="42dp"
                    android:layout_marginBottom="10dp"
                    android:layout_marginEnd="20dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="20dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/button_red"
                    android:text="Search"
                    android:textColor="@android:color/white" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <ProgressBar
                    android:layout_width="match_parent"
                    android:id="@+id/progressBar"
                    android:layout_height="match_parent" />

            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/result_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="50dp"></android.support.v7.widget.RecyclerView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>




</LinearLayout>

JAVA Code:

public class Search extends Fragment {

    private EditText mSearchField;
    private Button mSearchBtn;

    private RecyclerView mResultList;

    private DatabaseReference mUserDatabase;



    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_search, container, false);


        mUserDatabase = FirebaseDatabase.getInstance().getReference("Cars");


        mSearchField = (EditText) view.findViewById(R.id.search_field);
        mSearchBtn = (Button)  view.findViewById(R.id.search_btn);

        mResultList = (RecyclerView)  view.findViewById(R.id.result_list);
        mResultList.setHasFixedSize(true);
        mResultList.setNestedScrollingEnabled(false);
        mResultList.setLayoutManager(new LinearLayoutManager(getContext()));

        mSearchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String searchText = mSearchField.getText().toString();

                firebaseUserSearch(searchText);

            }
        });




        return view;
    }

    private void firebaseUserSearch(String searchText) {

        Toast.makeText(getActivity(), "Started Search", Toast.LENGTH_LONG).show();

        Query firebaseSearchQuery = mUserDatabase.orderByChild("title").startAt(searchText).endAt(searchText + "uf8ff");

        FirebaseRecyclerAdapter<Cars, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Cars, UsersViewHolder>(

                Cars.class,
                R.layout.list_layout,
                UsersViewHolder.class,
                firebaseSearchQuery

        ) {
            @Override
            protected void populateViewHolder(UsersViewHolder viewHolder, Cars model, int position) {


                viewHolder.setDetails(getActivity().getApplicationContext(), model.getTitle(), model.getDesc(), model.getImage(), model.getMileage(), model.getTrans(), model.getFuel(), model.getPrice(), model.getLocation());

            }
        };

        mResultList.setAdapter(firebaseRecyclerAdapter);

    }


    // View Holder Class

    public static class UsersViewHolder extends RecyclerView.ViewHolder {

        View mView;

        public UsersViewHolder(View itemView) {
            super(itemView);

            mView = itemView;

        }

        public void setDetails(Context ctx, String userTitle, String userDesc, String userImage, String userMileage, String userTrans, String userFuel, String userPrice, String userLocation){

            TextView user_title = (TextView) mView.findViewById(R.id.name_text);
            TextView user_desc = (TextView) mView.findViewById(R.id.status_text);
            ImageView user_image = (ImageView) mView.findViewById(R.id.profile_image);

            TextView user_mileage = (TextView) mView.findViewById(R.id.post_mileage);
            TextView user_trans = (TextView) mView.findViewById(R.id.post_trans);
            TextView user_fuel = (TextView) mView.findViewById(R.id.post_fuel);
            TextView user_price = (TextView) mView.findViewById(R.id.post_price);
            TextView user_location = (TextView) mView.findViewById(R.id.post_location);


            user_title.setText(userTitle);
            user_desc.setText(userDesc);

            user_mileage.setText(userMileage);
            user_trans.setText(userTrans);
            user_fuel.setText(userFuel);
            user_price.setText(userPrice);
            user_location.setText(userLocation);

            Glide.with(ctx).load(userImage).into(user_image);


        }




    }

When the Search Button is Clicked, i want it to open the new activity and load the results there



لینک منبع

android – How to use intents to open an activity that can have different ListView contents?


I am making an app that allows the creation of a gym workout schedule. My main activity includes a ListView (regular ArrayAdapter) with each item being a day of the week. When one item is clicked, a second activity is opened where there are EditTexts to enter the name and number of reps/sets for the exercise, as well as another ListView (custom adapter, called exerciseAdapter) for the exercises to be performed that day. There is also an Add button that adds the entered information of the exercise to the ListView. What I am trying to do is thatfor each different day that is pressed, there is a different displayed ListView of the second activity since there can be different gym schedules for different days of the week but my app currently shows the same schedule for any day pressed. I know that I need to use an intent to pass the position of the clicked ListView item, but I am not sure what to do with that intent in the second activity.

This is the code for my main activity:

public class MainActivity extends AppCompatActivity {

ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listView = findViewById(R.id.listView);
    ArrayList<String> daysOfWeek = new ArrayList<>();
    daysOfWeek.add("Monday");
    daysOfWeek.add("Tuesday");
    daysOfWeek.add("Wednesday");
    daysOfWeek.add("Thursday");
    daysOfWeek.add("Friday");
    daysOfWeek.add("Saturday");
    daysOfWeek.add("Sunday");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, daysOfWeek);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            Intent intent = new Intent(getApplicationContext(), WorkoutActivity.class);
            intent.putExtra("position", position);
            startActivity(intent);
        }
    });
}

}

This is the code for the onCreate of the second activity:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_workout);

    dbExercises = FirebaseDatabase.getInstance().getReference("exercises");

    Intent intent = getIntent();
    index = intent.getIntExtra("position", -1);

    exerciseNameET = findViewById(R.id.exerciseNameET);
    setsET = findViewById(R.id.setsET);
    repsET = findViewById(R.id.repsET);
    restTimeET = findViewById(R.id.restTimeET);
    addButton = findViewById(R.id.addButton);
    exerciseList = findViewById(R.id.exerciseList);

    exercises = new ArrayList<>();

    exerciseAdapter = new ExerciseList(WorkoutActivity.this, exercises);
    exerciseList.setAdapter(exerciseAdapter);

    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            addExercise();
        }
    });
}



لینک منبع

android – Navigating to parent activity


I have two flavors one is free and another one is paid

I have the code only in main—> Java folder trying to figure the code which is free and paid and leaving free and paid folders empty.

Now I have MainActivity which launches from that user navigates to Activity A, Activity B…

When User goes to Activity A and perform some operations he would like to navigate to parent activity ie…MainActivity he clicks on up navigation.

Here comes the problem

When he clicks up navigation how do I come to know he has to go to parent activity using flavor

I have set up my gradle file as shown below:

 productFlavors {
    free {
        applicationId "com.abc.xyz.free"
        versionName "${versionMajor}.${versionMinor}.${versionBuild}"
        buildConfigField "boolean", "PAID_VERSION", "false"
        resValue "string", "android:value", applicationId
        dimension "version"
    }

    full{
        applicationId "com.abc.xyz.full"
        versionName "${versionMajor}.${versionMinor}.${versionBuild}"
        buildConfigField "boolean", "PAID_VERSION", "true"
        dimension "version"
    }
}

I’m unable to figure how does I change the android value in manifest file :

  <activity
        android:name=".ActivityA"
        android:label="ActivityA"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden"
        android:launchMode="singleTop">
        <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"></meta-data>
    </activity>
    <activity
        android:name=".ActivityB"
        android:label="ActivityB"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden">
        <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"></meta-data>
    </activity>



لینک منبع

php – Blank Screen when adding a moodle (3.1.7) activity to a course


I have installed a LAMP with PHP 5.4.16, Maria DB and Moodle 3.1.7 on Red Hat Enterprise Linux 7.

When i am pressing the Button “Add an activity or ressource”, the popup opens to select the activity/ressource, but when i click the “Add”-Button i get a blank screen (Chrome says HTTP 500).

What can be the origin of this?

With best regards,
Bjoern



لینک منبع

java – More than almost 30 Media Players in an activity don’t start in android programming


I have a project and about 37 button in an activity that they play a sound by media player but when I press about 30 buttons the rest of the buttons won’t start and the buttons do nothing . Here is a little part of my code :

import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    MediaPlayer mediaPlayer;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mediaPlayer = MediaPlayer.create(this, R.raw.ability);
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mediaPlayer.isPlaying()) {
                    mediaPlayer.seekTo(0);
                }else {
                    mediaPlayer.start();
                }
            }
        });
    }
}

Please Help Me !!!!!



لینک منبع